• 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

request input on client/server design

 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

I'm considering doing a project that involves collaborative client/server application involving chat, whiteboard, VoiP, etc.

My question is this...would each aspect of the project (chat, whiteboard,etc) require that it run on a seperate port to the server? Is that normal from a design perspective? I'm thinking a seperate thread on the server listening on different ports: one for the chat (port 2000), one for the whiteboard(port 2001), one for VoiP(port 2002), etc.

I'm only thinking of this approach as being favourable because the types of data being moved back and forth would be different on each port. Does this make sense? Are there some other approaches to this type of project?

Alan
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think there's any problem with using several ports that way. A single port might make life a lot easier if you have to get them opened on a firewall. It also simplifies what clients have to know about the server.

You can accept all request messages on one port and dispatch them to appropriate subsystems based on content. Read up on Strategy Pattern and see if this make sense:

The header might be CHAT or WHITEBOARD. The HandlerFactory might just be a HashMap where CHAT returns a ChatRequestReader. I like factories like that because you can add new headers and handlers through configuration without touching the dispatcher code.

Does that sound useful? Are you comfortable managing multiple threads for inbound requests?
 
Alan Shiers
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've used multi-threading before in standalone apps but not when trying to configure a server app.

Perhaps you can direct me to a tutorial or something that explains your idea in greater detail?

Alan
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The classic socket server does something like:

This runs each new request on a new thread. In Java5 and later with only a couple more lines you can run requests on a thread pool to reduce thread setup and teardown. Does that look like something you can use?
 
Alan Shiers
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Stan James:



I'm more interested in this snippet of code. This seems to suggest that I can somehow read each packet as it comes in and determine if is of a particular protocol. Is that possible? Certainly it would be good to read the packets as they arrive so that I can then determine to which handler to send them.

Alan
 
reply
    Bookmark Topic Watch Topic
  • New Topic