Solved

SocketChannel

Posted on 2003-11-07
5
213 Views
Last Modified: 2010-03-31
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.  
0
Comment
Question by:skyblue01
  • 3
  • 2
5 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 150 total points
ID: 9700317
 Yes, you can use the same socket if you want to.
0
 

Author Comment

by:skyblue01
ID: 9700362
Thanks girionis.   And I'd assume that this won't cause problems for the connection states, would it?  
0
 
LVL 35

Expert Comment

by:girionis
ID: 9700398
 No, the client shouldn't have problems and since you are using the nio API then you can use Selectors on the server to manage several simultaneous socket connections to one thread.
 
0
 
LVL 35

Expert Comment

by:girionis
ID: 9700405
 Just make sure that no other component outside the thread on the client has access to the socket (input and output streams).
0
 

Author Comment

by:skyblue01
ID: 9700514
k
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question