Hello, in the absence of experience and knowledge I can not understand the problem, I hope for help. I have a simple C # server socket written on my PC

try { IPAddress localAddress = IPAddress.Parse(""); Socket listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPEndPoint ipEndpoint = new IPEndPoint(localAddress, 5555); listenSocket.Bind(ipEndpoint); listenSocket.Listen(1); while (true) { Console.WriteLine("Server wait {0}", ipEndpoint); Socket handler = listenSocket.Accept(); Console.WriteLine("Connect with {0}", handler.RemoteEndPoint); Console.WriteLine("Send message.."); handler.Send(encoding.GetBytes("I'm wait")); Console.WriteLine("Close connect"); handler.Close(); } } catch (Exception e) { Console.WriteLine("Error: {0}", e.ToString()); } } } 

And socket client on android

 public class ClientActivity extends Activity { EditText textOut; TextView textIn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_client); textOut = (EditText)findViewById(R.id.editText1); Button buttonSend = (Button)findViewById(R.id.button1); textIn = (TextView)findViewById(R.id.textView1); buttonSend.setOnClickListener(buttonSendOnClickListener); } Button.OnClickListener buttonSendOnClickListener = new Button.OnClickListener() { //@Override public void onClick(View arg0) { // TODO Auto-generated method stub Socket socket = null; DataOutputStream dataOutputStream = null; DataInputStream dataInputStream = null; try { socket = new Socket("", 5555); dataOutputStream = new DataOutputStream(socket.getOutputStream()); dataInputStream = new DataInputStream(socket.getInputStream()); dataOutputStream.writeUTF(textOut.getText().toString()); String readUTF = dataInputStream.readUTF(); textIn.setText(readUTF); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } finally{ try { if (socket != null){ socket.close(); } if (dataOutputStream != null){ dataOutputStream.close(); } if (dataInputStream != null){ dataInputStream.close(); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (dataOutputStream != null){ try { dataOutputStream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (dataInputStream != null){ try { dataInputStream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } ;} 

I am very bad at this, the whole code is nuggul. If from the android in the browser enter the address and port, the server sees the connection. And through the application on the phone, nothing happens. Help please advice, what's wrong?

  • what's in the log? Internet rights in the manifest added? - Gorets
  • it is difficult to write like this when all the code is googled. Without a log, it will really be hard for you to suggest something useful. My option is that you have, for example, developer.android.com/reference/android/os/… - rasmisha
  • one
    thanks, apparently you need to try using AsyncTask - Bigaloy
  • @Bigaloy if the code doesn’t work, then it won’t work with AsyncTask anymore + earn yourself a debug with debugging with threads ... logs at least and learn what LogCat is - Barmaley