Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Server/Client Programming - Guidance require  RSS feed

 
Em Aiy
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a client server chat applications. I have few concerns which i am not sure how to deal with (since i have never worked on java core). So asking for your guidance

  • I am thinking to write some protocol for it. ie. (command_type + [data length + data]). The command type could be any combination of a single byte, which will decide that it can have "Data" or "no Data". What i want to do, is to write a base class for each command having same incoming/outgoing data. and then that class object is written in stream and read from stream. i.e i dun want to use inputStream.readline .. i want to read it generically using objects. how would i? I want it like .. i want to read the first byte of message and then that byte would be a COMMAND_TYPE which would be used as input in command_object_factory to get some object which would automatically read the rest of the stream.



  • There could be multiple clients, talking to each other with one server. should each client be handled through separate server thread?


  • For client/client chat. should i include server in it. i.e message from client 1 will first go to server and then to client 2 - or it would be like first authentication > then client 1 and client 2 will be connected directly and then chat can be done


  • Thanks
     
    Joe Ess
    Bartender
    Posts: 9406
    12
    Linux Mac OS X Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Muhammad Ali wrote:
  • I am thinking to write some protocol for it. ie. (command_type + [data length + data]).


  • Consider using Remote Method Invocation. It wraps socket-level communication in a handy object interface. Much easier than dealing with bytes at the socket level.

    Muhammad Ali wrote:
    There could be multiple clients, talking to each other with one server. should each client be handled through separate server thread?


    That is one way. Another option is to have a thread pool.

    Muhammad Ali wrote:For client/client chat. should i include server in it. i.e message from client 1 will first go to server and then to client 2 - or it would be like first authentication > then client 1 and client 2 will be connected directly and then chat can be done


    Either way. It is probably easier to do with the server included because you have well-defined roles and you just have to concentrate on routing messages.
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!