Results 1 to 4 of 4
  1. #1
    gwaldarick is offline Member
    Join Date
    Dec 2008
    Rep Power

    Default Multithread Chat server/client

    I am interested in making a multithreaded chat client and server program.
    I tried looking online for examples, but everytime i try to compile it says
    "uses or overrides a deprecated API."
    it doesnt even allow me to create the .class files as usual? :/
    do any of you lovely people know how to make just a basic 'Multithreaded' chat system(multiple people at the same time), that will not give me deprecated API errors?

    thanks in advance :D

  2. #2
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Rep Power


    Read about ServerSocket, Socket and threads. Essentially, you create a ServerSocket on your "server" machine, then sit in a loop calling accept(). Every time that returns with a Socket, pass that socket to another thread for processing.

    You'll obviously need to invent some "protocol" for how your client makes requests to the server -- what bytes/strings you send for "please log me on as X", "please tell me who's logged on", "please start a chat with Y", "please send this message to Y" etc, and think about how you'll manage e.g. chats from 1 client to multiple people. You'll also need to think about how your client "polls" for messages and/or how you handle the "two directions" of a conversation (you need to send a command to the server at a given moment, but it needs to send you a chat message at a given moment). Two connections can alleviate this, but some firewalls don't allow it.

    I assume this is a small project for now. If it was a serious chat system expecting to have large numbers of clients connected, you'd have to think about using something like the Selector class to make it scale (Selector allows thousands of simultaneous connections; with a thread per connection, you'll probably max out somewhere in the low hundreds).

  3. #3
    gwaldarick is offline Member
    Join Date
    Dec 2008
    Rep Power

    Default Next step

    Thankyou for the advice, I have refined what I am trying to accomplish.

    new goal: Multiple chat clients talking to each other.
    so the Server can make new threads for each connection (need some help how to do this), and can be sent a string from a client.
    When it receives it from the client, it send out the message to all clients.
    Anybody have any ideas on this?

    imagine a chat box in a mmorpg, with all the players talking in a general/world chat.

  4. #4
    almeidamiguel is offline Member
    Join Date
    Sep 2009
    Rep Power


    Hello Gwaldarick,
    I'm with the same problem as you, did you got some samples, can you send me please?

    Thanks in advanced

Similar Threads

  1. Chat Client
    By Jessi34 in forum New To Java
    Replies: 5
    Last Post: 12-09-2009, 04:49 PM
  2. Multi Client/Server Chat Question
    By Kodak07 in forum Networking
    Replies: 3
    Last Post: 03-29-2009, 10:50 PM
  3. Replies: 1
    Last Post: 10-05-2008, 03:12 PM
  4. Replies: 2
    Last Post: 07-28-2008, 07:32 PM
  5. Identify Client in Socket Client Server Application
    By masadjie in forum Networking
    Replies: 1
    Last Post: 12-20-2007, 10:18 AM

Posting Permissions

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