我想連接到應用服務器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