Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

request input on client/server design

 
Alan Shiers
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • 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
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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
  • 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)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic