Solved

SocketChannel

Posted on 2003-11-07
5
215 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

707 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