File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes Socket and threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Socket and threads" Watch "Socket and threads" New topic
Author

Socket and threads

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi!
I have a problem. I have a program using socket server communication and it works fine as long as I only have one user at time.
The flow of the program is
Receiver waiting for messenger
Sender send message, and start to wait for a response message
Receiver get message, and send a response message, start waiting for a now message.
And so on�
To day I can only send one question at time (can only have one user) but I want to have many�
Is it possible to solve with threads? And in that case, does anybody have an example of hove to solve it.
Thanks!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

Yes, you can solve this using threads. Basically, what you do looks something like this:

Of course, there are complications. But that's the basic idea.


[Jess in Action][AskingGoodQuestions]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Your example is pretty much exactly what I'm doing right now. Creating and discarding a thread per request is easy, but not the most efficient. What's the next step up the ladder of complexity, scalability and robustness? Thread pooling?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Socket and threads