Win a copy of Pragmatic AI this week in the Artificial Intelligence 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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
Ranch Hand
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!