[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

SocketChannel

Posted on 2003-11-07
5
Medium Priority
?
218 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 600 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

649 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