java - Android:socket communication -
I'm trying to create simple app with Android client and Java server to send messages to Android client server (Java) When I try to read the server response error: Socket Closed Line (If Received (Received Message = Received.readline ()) = Faucet) =))
Public Class Client Connector Task Async Task & lt; String, zero, integer & gt; {Private Socket Client; Private PrintWriter PrintRighters; Validate protected integer doInBackground (string ... strings) {// input parameters if (string.label = lt; = 0) {return 0; } // Connect to the server and try the message {client = new socket ("192.168.1.4", 7777); Printwriter = new printritter (client.getOutputStream (), true); // while (true) {InputStream istream = client.getInputStream (); Get BufferedReader = New BufferedReader (New InputStreamReader (istream)); String received message; While (true) {// printwriter.write (wire [0]); Printwriter.print (wire [0]); Printwriter.flush (); Printwriter.close (); If ((receiveMessage = get read.readline ())! =) // server {System.out.println (receiveMessage); // display at the DOS prompt}} //} //client.close (); } Hold (unknownhostexception e) {e.printStackTrace (); } Hold (IOException e) {e.printStackTrace (); } Return 0; } Zero on safe exempt (long result) {return; }}
shutting down PrintWriter inside the loop ' Do not understand, and it closes before the readLine () call, there is no point in either the code or other stream by closing the input or output stream of socket And the socket closes.
Comments
Post a Comment