aspose file tools*
The moose likes Java in General and the fly likes ServerSocket and thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "ServerSocket and thread" Watch "ServerSocket and thread" New topic
Author

ServerSocket and thread

A Agr
Ranch Hand

Joined: Feb 10, 2009
Posts: 32
I have 4 ServerSockets running at say port 1,2 ,3 4

A ServerSocket at port 1 listens for incoming connection from different clients and read from and write to clients. A socket connection can be created at any ServerSocket to write at other ServerSocket




Main class x creates serversocket and passes it to thread and waits for client connection and if got any , processes it. Along with this at same while(true){}loop next to it in class x also executes.Both should work simultaneously

When I run it, I get some problems

1. After a while I get Connection refused exception/// like it works for say 1 min and starts throwing exception
2. while true() loop is also continously writing to ServerSocket at say port 2. Output at port 2 becomes..print java..print java..
but i want it work like print jsp print java print jsp print java
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

This question does not have anything to do with SCJP. A moderator will move it shortly


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3825

I'm not sure what you are trying to do here.. But "Socket l = p.accept();" is blocked until client made a connection to that particular port the ServerSocket is created to listen. How are you spawning new thread(s)? Can't see that in your code.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ServerSocket and thread