我想连接到应用服务器Java的客户端Android,但没有工作。这是代码:Java服务器和Android客户端不会连接
Android客户端;
_cb_led1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Socket mySocket = new Socket("127.0.0.1", 9090);
PrintStream p = new PrintStream(mySocket.getOutputStream());
p.println("Mensaje");
}
});
Java服务器:
s = new ServerSocket(9090);
sc = s.accept();
System.out.println("Conexión establecida");
b = new BufferedReader(new InputStreamReader (sc.getInputStream()));
while (true)
{
mensaje = b.readLine();
System.out.println(mensaje);
}
b.close();
sc.close();
s.close();
}
catch (IOException e)
{
System.out.println("No puedo crear el socket");
}
}
任何建议
非常感谢你
定义“没有工作”。我们没有ESP。 –
Android中的localhost不会尝试连接到它本身吗?见[这篇文章](http://stackoverflow.com/questions/2301560/java-net-connectexception-127-0-0-18080-an-android-emulator)。 –
你会得到什么样的错误? – Lycha