Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ServerSocket and thread

 
A Agr
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question does not have anything to do with SCJP. A moderator will move it shortly
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic