I have an android app which will create a ServerSocket and accept a socket. I want it can communicate(read/write) with remote device.
My sample code like following:
mListenSocket = new ServerSocket();
mListenSocket.setReuseAddress(true);
mListenSocket.bind(new InetSocketAddress(DOCK_PORT));
mSocket = mListenSocket.accept();
Thread {
loop {
outputStream = mSyncSocket.getOutputStream();
inputStream = mSyncSocket.getInputStream();
...
inputStream.read(data)
outputStream.write(data);
...
}
}
It can read right inputStream data from client, but the second time read() always return -1 after I write data in outputStream firt time .
I have no idea about this issue. Somebody can give me some tips? Thanks a lot.
======================================================================
I think I need to express my problem more clearly.
There are two devices(A, B), and their workflow as follows:
Type 1 task:
1. A sends command to B
2. B receives command and reply message to A
3. A receives message, Done.
Type 2 task:
1. A sends command to B, Done.
Above tasks are asynchronized.
My old method was that create a ServerSocket on A and B device respectively to handle A->B and B->A communication.
I think maybe one socket can resolve above task, but one socket will encounter read -1 issue.
Someone can give me more advices? Thanks a lot.