• 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

concurrent server

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

i am trying to make a program which has a server and a multiple clients. i create a new thread each time a client connects to the server. how can i get the server to recieve some data from one client and then pass it on to another client. should i create new threads of servers each time i accept a connection or just have one main server?. im dont have that much knowledge about threads and find them quite difficult. does anyone know of a good site that has an example of what im trying to do

thanks
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's an example in the Java Tutorial Custom Networking Chapter and another example here. Creating threads has some overhead, so it is common to create a number of threads in a pool and reuse them.
As for passing messages to other clients (sounds like a chat program), the server has to keep track of all the clients and distribute incoming messges to each of them.
The most basic technique in programming is to split your big problem into smaller ones. Create simple proof-of-concept programs, like two peers that connect to each other and exchange messages, or a server that exchanges messages between two clients, then try to introduce multithreading to service more clients. Don't get bogged down in protocols or fancy functionality. Get something working. Once you get the basics down, think about building upon the basics to create more complex systems.
reply
    Bookmark Topic Watch Topic
  • New Topic