Home > Mobile >  Android socket
Android socket

Time:12-25


inside onCreateNew Thread (new Runnable () {
@ Override
Public void the run () {
Try {
The socket=new socket (" 192.168.0.126 ", 10010);
InputStream InputStream=socket. GetInputStream ();
byte[] buffer=new byte[1024];
int len;
BufferedReader reader=new BufferedReader (new InputStreamReader (socket. GetInputStream ()));
String STR="";
While (true) {
//if a socket connection to the server, and the input stream not closing
If ((STR=reader. ReadLine ())!=null) {
STR +="";
}
}
//while ((len=inputStream. Read (buffer))!=1) {
//String String data=https://bbs.csdn.net/topics/new (buffer, 0, len);
////to the main thread of data received in the
//the Message Message=Message. Obtain ();
//the message. What=1;
//message. Obj=data;
//handler. SendMessage (message);
//}
} the catch (IOException e) {
e.printStackTrace();
}
}
}).start();
Why serversocket data
While ((len=inputStream. Read (buffer))!=1) can be read automatically calls the method
While (true) does not perform
Seek a great god advice thanks a lot

CodePudding user response:

You this dead loop directly, another readLine is read a newline FuCai returns as a result, if there are no line breaks return data, also can't return the result
  • Related