Hi,
I am implementing a server that reads for socket connections at a
port, and processes the socket on a separate thread. We do not control
the client implementation. Here is the scenario.
0. Client connects to the socket.
1. Client writes to the socket.
2. Server reads from the socket.
3. Client waits for the response on the socket
4. Server writes to the socket.
5. Socket is closed.
Incoming request on the socket is not guaranteed to be terminated with
any particular sequence of characters. How does the server know how
many bytes to read, and when to stop reading?
Here are couple of things I tried.
1. readln on a buffered reader on the server side would block till it
receives the "eol" character.
2. I have tried reading x number of characters at a time, and thought
if number of characters read are less than the attempted number of
characters to read (or the read method returns -1) then read all the
data sent by the client. This works if the attempted characters to
read initially, are greater than the number of characters sent by the
client, but not if it is the other way.
I have used BufferedReader, and the PrintWriter classes.
I appreciate your help in resolving this issue.
Thanks.
I am implementing a server that reads for socket connections at a
port, and processes the socket on a separate thread. We do not control
the client implementation. Here is the scenario.
0. Client connects to the socket.
1. Client writes to the socket.
2. Server reads from the socket.
3. Client waits for the response on the socket
4. Server writes to the socket.
5. Socket is closed.
Incoming request on the socket is not guaranteed to be terminated with
any particular sequence of characters. How does the server know how
many bytes to read, and when to stop reading?
Here are couple of things I tried.
1. readln on a buffered reader on the server side would block till it
receives the "eol" character.
2. I have tried reading x number of characters at a time, and thought
if number of characters read are less than the attempted number of
characters to read (or the read method returns -1) then read all the
data sent by the client. This works if the attempted characters to
read initially, are greater than the number of characters sent by the
client, but not if it is the other way.
I have used BufferedReader, and the PrintWriter classes.
I appreciate your help in resolving this issue.
Thanks.
Comment