Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Python Continuous Integration and Delivery this week in the Python 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
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

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!