This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

TCP mutiple connections  RSS feed

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to keep my skills up since I don't get to code at work and I am visiting some old college projects and trying to improve on them. I have a generic TCP server and client. I am trying to get the TCP server to accept multiplt connections. I know that I need threads, but can't figure it out. Do I listen on the socket and then spawn a new thread when ever a client tries to connect? If someone could type in some quick pseudocode that would be greatly appreciated. I don't need actual code, just some pseudocode to get me started. Thanks a bunch.
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Jack Dawson:
Do I listen on the socket and then spawn a new thread when ever a client tries to connect?

Da.In the ConnectionHandler, you just talk to the socket and close it when you're done. If performance is important you would use a thread pool rather than spawning new threads for every client (and if performance is really important and you can afford to be cutting edge, look into JDK 1.4 java.nio.*).
HTH
- Peter
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!