0

I am trying to make communication between my mobile and my PC. I use socket to do this. The server in mobile side start successfully and it show there is a request coming from my PC's browser, it shows me the request is from IP 192.168.1.100 which is my PC's LAN IP, it's correct. However, from mobile it cannot send a message back to PC. Here is the sample code.

Response status:

Socket socket = client;
OutputStream out = socket.getOutputStream();
m_activityMain.handler.sendMessage(
       m_activityMain.handler.obtainMessage(1,socket.getInetAddress().getHostAddress()));

String response = "";
response += "HTTP/1.1 200 OK\r\n";
response += "Content-Type: text/html\r\n";
response += "\r\n";
out.write(response.getBytes());
out.write(new Boolean(this.isAlive()).toString().getBytes());// output status
Thread.sleep (1000);
out.flush();
out.close();
reader.close();

In browser, it always shows connection stop error and cannot display this message, I don't know why?

2
  • Maybe it’s because you close the connection? Do you listen for incoming data?
    – Laurence
    Dec 28, 2012 at 16:24
  • yes. It shows the HTTP request information from browser.
    – panda
    Dec 28, 2012 at 18:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.