从服务器接收到数据后,它将等待直到套接字连接。套接字关闭后,它将开始发送一些特殊字符,如下所示:而这是从服务器接收的数据“ 01 01,500,0002”
04-01 17:55:27.185 15248-15495 / com.wings.administrator.myapplication I / read line:01 01,500,0002
04-01 17:55:27.814 15248-15495/com.wings.administrator.myapplication I/chatty: uid=10490(com.wings.administrator.myapplication) Thread-5 identical 28 lines
04-01 17:55:27.837 15248-15495/com.wings.administrator.myapplication I/read line: 01 01,500,0002
04-01 17:55:27.861 15248-15495/com.wings.administrator.myapplication I/read line: 01 01,500,0002
04-01 17:55:28.140 15248-15495/com.wings.administrator.myapplication I/chatty: uid=10490(com.wings.administrator.myapplication) Thread-5 identical 12 lines
04-01 17:55:28.163 15248-15495/com.wings.administrator.myapplication I/read line: 01 01,500,0002
04-01 17:55:28.186 15248-15495/com.wings.administrator.myapplication I/read line: 01 01,500,0002
最后,应用程序因以下错误而崩溃,但它不会影响我的代码中的任何行。
E/libc++abi: terminating with uncaught exception of type std::bad_alloc: std::bad_alloc
04-01 18:05:02.138 15248-15495/com.wings.administrator.myapplication A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 15495 (Thread-5), pid 15248 (r.myapplication)
04-01 18:05:02.139 15248-15261/com.wings.administrator.myapplication W/libc: pthread_create failed: couldn't allocate 1036288-bytes mapped space: Out of memory
04-01 18:05:02.139 15248-15261/com.wings.administrator.myapplication E/libutils.threads: androidCreateRawThreadEtc failed (entry=0xf1f65e71, res=11, Success)
(android threadPriority=0)
public void run() {
try {
socket = new Socket( eHostIp.getText().toString(), Integer.parseInt( eHostPort.getText().toString() ) );
socket.setTcpNoDelay(false);
BufferedReader in = new BufferedReader( new InputStreamReader( socket.getInputStream() ), 1024 );
eReceiveData.setText( "Server Connected... XXXXXXX" );
String line = " ";
while ((line += (char)in.read()) !=null) {
Log.i( "read line", line );
eReceiveData.setText( line );
}
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} );
thread.start();
}