Results 1 to 4 of 4
  1. #1
    f0ns is offline Member
    Join Date
    Oct 2009
    Location
    Belgium
    Posts
    4
    Rep Power
    0

    Default Multithreaded Client/Server Chat program

    Dear readers,

    I have to make a Multithreaded Client/Server Chat program for one of my courses (for school). I've been looking around on the internet and gathered pages of information on this subject by now.

    Design is one of the most important aspects of this application and that is why this topic is born.

    I would like to share my ideas and I hope anyone can help/point me out in a direction to improve my design.

    The Plan:

    Server:
    - Thread that listens for hosts that try to connect (authenticated hosts get added to a list)

    Client:
    - The Host connects to server
    - Clients have 2 threads (one for sending messages to server and one for receiving messages from server)


    The basis idea is when a Client sends a message (which is an object => serialization). The server receives this message and "broadcasts" it to the other clients. I would also like to add multicast (use of chatrooms) and unicast (private messaging) in a later stage.

    Any thoughts or ideas?

    Extra Notes:

    Server:

    - usage of singleton (I only want one server running at a time)
    - usage of ServerSocket
    - usage of Socket
    - usage of ObjectInputStream & ObjectOutputStream

    - class ServerThread (extends Thread)
    - class message (object to be serialized) => contains the message, author, date&time)


    Client:

    - usage of Socket
    - usage of ObjectInputStream & ObjectOutputStream

    - 2 classes (extends Thread) => listening for messages from server + sending messages to server???
    - class message (object to be serialized- => contains the message, author, date&time)

    Problems:

    - do I want to write the class message 2 times (in the Client & Server application?! How can I fix this!? => better design possibility?)
    - sending objects over the network a wise idea?!
    - do I need to use a protocol? how do I implement this?
    - ...

    ps. I'm pretty familiar with how Java works so this isn't a "please help me create some code" topic, i'm only interested in improving/creating the best design :). This assignments needs to be ready in 6 weeks, when I've handed in my work and received a grade i'll post it here for people to use!
    ps. Sorry for bashing this big wall of text upon your screen :D
    Last edited by f0ns; 10-21-2009 at 11:45 AM.

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    812
    Rep Power
    6

    Default

    Better start with a psudocode and then start writing the code.If u come across any problem,the people can help you.
    Ramya:cool:

  3. #3
    f0ns is offline Member
    Join Date
    Oct 2009
    Location
    Belgium
    Posts
    4
    Rep Power
    0

    Default

    Quote Originally Posted by RamyaSivakanth View Post
    Better start with a psudocode and then start writing the code.If u come across any problem,the people can help you.
    I'll make some Use Cases tonight, writing pseudocode just looks like one big time waste to me...

    Also I want to note that the keypoint is not to get the code working, cause that won't be the problem. The keypoint is that alot of thought is put in the construction of this application before I start writing even 1 single line of code!

    I always learned Analysing is one of the key essences in programming, this isn't my strongest point (yet)! That's why I created this topic. Any people familiar with designing multithreaded networking application that have some advise for me? or some essential stuff that will improve my design?

    The Classes i'll use:

    Server
    Domain:
    - Server
    - ServerThread (extends Thread)
    - Message (Serializable)
    - User (Serializable)

    GUI:
    - serverFrame => after giving up name + port for the server you can fire the server up, once the server is fired you'll have a big JTextArea where you can monitor the server (new connections, ....)

    Client
    Domain:
    - Client
    - Classes for threading?
    - Message (Serializable)
    - User (Serializable)

    GUI:
    -connectFrame => after giving up the server address, server port and the desired nickname, the server will authenticate you. Once this is succeeded you'll proceed to the chatFrame
    -chatFrame => this is the place where you can typ stuff to other people. You can see the people who are online. extra functionality here will be added later.

    Design Issues:
    Do I really need to User, Message both in the user and server application (same code). These objects will be put on the streams. User will be used for authenticating a user and Message to store messages in. Any suggestions?

    Do I have to work with 2 different threads on the Clients side? One that is gonna accept messages from the server and one that sends messages to the server?

    thanks in advance, if I didn't scare you away by now!
    Last edited by f0ns; 10-21-2009 at 03:48 PM.

  4. #4
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    5

    Default

    On the server portion... you will need to have a thread per client socket to listen for data coming in. Unless you plan on using NIO sockets (i would avoid NIO for a school assignment because of it's complexity).
    Last edited by mrmatt1111; 10-21-2009 at 05:32 PM.
    My Hobby Project: LegacyClone

Similar Threads

  1. Multithread Chat server/client
    By gwaldarick in forum Advanced Java
    Replies: 3
    Last Post: 09-19-2009, 12:22 AM
  2. [SOLVED] UDP chat client server
    By Koren3 in forum Networking
    Replies: 2
    Last Post: 04-25-2009, 01:51 AM
  3. Help with chat client program
    By srivigneshwar in forum New To Java
    Replies: 1
    Last Post: 04-03-2009, 06:32 PM
  4. Multi Client/Server Chat Question
    By Kodak07 in forum Networking
    Replies: 3
    Last Post: 03-29-2009, 10:50 PM
  5. Replies: 2
    Last Post: 12-27-2008, 08:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •