• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ServerSocket and thread

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question does not have anything to do with SCJP. A moderator will move it shortly
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic