HI to All,
I guess u cannot really go too far from JavaRanch, U Keep coming back to it.
There are certain problems I am facing in using sockets.
1. Once i do a getInputStream() from a socket, do i need to explicitly close it before i close my socket?
2. What if i call socket.getInputStream() twice in my program, do i ve to make sure that the previous one is closed before i open the next one.
3. typically what exactly means by closing the inputStream of a socket. I hope i am not sending any FIN to my peer to close down the socket.
4. Now this problem is more intricate. So all the
Java Networking gurus.. Hold ur breadth.
My clients ( possibly many 100's for example) will connect to my TCP server
thread that blocks on "accept".
Now i dont want to create a new thread for each accepted socket (to do the communication with the client).
hence i created a TCP Communication thread(TCPComm class) that maintains a List of sockets that have been "accepted" by the TCP server.My TCPComm thread tries to read the sockets in the List in a for loop ( each socket setSoTimeout has been 1 msec- to make it nonblocking ).
My clients will write to the connected socket, and the data that they write will vary in length.
Now the TCPComm tries to read the
Header the client writes which contains the size of the data coming Your way.
Now my problem is :
If suppose i m unable to read the full data,
I will somehow have to remember what all data has been read and how much is still to come for each socket(client).
Now kindly let me know How to approach this problem.
Shud i use DataInputStream and use the mark and reset mechanisms given by these streams.
or explicitly code for remembering how much i ve already read and how much is tsill to come in my buffer?