Posted on 2003-11-07
My client is sending a message into the byte buffer to the SocketChannel sc. Right after it sends it to the server, it starts a background thread for receiving any incoming messages. In the run() method of the Client class which extends Thread, I'm using this same SocketChannel sc (field variable) to read bytes of data into the buffer to get the message. Is this legal or do I have to create a new SocketChannel in run() designed specifically for this message retrieving purpose? Please let me know. This is part of the simple chat program where the client sends a message to the server which the server redirects it back to all the connected clients. Thanks.