Sockets j2me-j2se套接字连接
我正在开发一个j2me应用程序,它使用套接字通过WiFi向PC发送数据。服务器地址应该是什么?i、 e.在下面的代码中,我应该使用什么来代替“localhost” 客户端代码(j2me): 服务器代码(j2se):Sockets j2me-j2se套接字连接,sockets,java-me,wifi,midp,Sockets,Java Me,Wifi,Midp,我正在开发一个j2me应用程序,它使用套接字通过WiFi向PC发送数据。服务器地址应该是什么?i、 e.在下面的代码中,我应该使用什么来代替“localhost” 客户端代码(j2me): 服务器代码(j2se): 这取决于服务器的ip/域 如果您在本地网络(家庭/办公室)上运行东西,那么只需了解运行服务器代码的机器的ip是什么。 在linux系统中,您可以通过命令ifconfig找到,然后在输出中,ip地址位于inet addr下。在windows系统中,使用ipconfig/all 一旦您拥
这取决于服务器的ip/域 如果您在本地网络(家庭/办公室)上运行东西,那么只需了解运行服务器代码的机器的ip是什么。 在linux系统中,您可以通过命令ifconfig找到,然后在输出中,ip地址位于inet addr下。在windows系统中,使用ipconfig/all 一旦您拥有了运行服务器的机器的ip,只需将它而不是您正在客户端中使用的本地主机 但是,如果您希望在公共网络上使用此功能,则必须在具有(或使用)的计算机上运行服务器代码
SocketConnection sc = (SocketConnection)
Connector.open("socket://localhost:9002");
DataOutputStream os = null;
try{
os = sc.openDataOutputStream();
os.writeUTF("Test Dama");
} finally{
sc.close();
os.close();
}
ServerSocket echoServer = null;
String line;
DataInputStream is;
Socket clientSocket = null;
try {
echoServer = new ServerSocket(9002);
}
catch (IOException e) {
System.out.println(e);
}
try {
clientSocket = echoServer.accept();
is = new DataInputStream(clientSocket.getInputStream());
line = is.readUTF();
System.out.println("Received:"+line);
}
catch (IOException e) {
System.out.println(e);
}