Sunday, March 2, 2014
Help: socket latecomer data immediately close, resulting in not sending data
/ / Create socket connection
SocketAddress socketAddress = new InetSocketAddress (serverIp, port);
Socket socket.connect (socketAddress, 1000);
/ / Send data
String data = "test .....";
OutputStream out = socket.getOutputStream ();
OutputStreamWriter writer = new OutputStreamWriter (out, "UTF-8");
writer.append (data);
writer.flush ();
/ / Close the socket connection
socket.shutdownInput ();
socket.shutdownOutput ();
socket.close ();
Code is probably accomplished, the recipient does not receive the data sent here.
I do not know where the problem is, anybody know?<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Your confirmation code have reached what, nothing abnormal Mody, see logcat
Reply:
socket only write data to the buffer, the buffer is still not given the actual data go.
You should receive the other side of the data you send, send you back a confirmation after you receive the confirmation and then close the socket, so there is not the problem.
Reply:
Code went;
In addition to wait until after the close ack socket, there are other ways?
Reply:
After each received data close socket, if you detect socket closed
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment