cleint server chat

Posted on 2006-05-11
Last Modified: 2008-03-10
i want to make java simple java program (as client and server )

i want 1 server

and maluti client
i use socket to make connection between client and server

the problem is

i want the client able to send recive (at the same time)

when the server send message will send to all client
my client can revice this message and send any other message to server

i use this code in client
to send data and recive data

         BufferedReader br = new BufferedReader(new InputStreamReader(;
      try {
      } catch (IOException ioe) {
         System.out.println("IO error trying to read your name!");
                     Socket s = null;
                  int serverPort = 7896;
                  s = new Socket("localhost",serverPort);
                  DataInputStream in = new DataInputStream(s.getInputStream());
                  DataOutputStream out = new DataOutputStream(s.getOutputStream());
                  String data = in.readUTF();
                  System.out.println("Received: "+data);
      }catch (UnknownHostException e){
            System.out.println("Sock: "+e.getMessage());}
            catch(EOFException e){System.out.println("EOF:"+e.getMessage());}
            catch(IOException e){System.out.println("IO:"+e.getMessage());}
                  catch(IOException e){

this code just send data once and recive one

i want this code to recive and listen to server all time

how can make this ??
see this code
Question by:bob20062006
    LVL 92

    Accepted Solution

    LVL 14

    Assisted Solution

    > this code just send data once and recive one
    you need a multithreaded server
    this book has been written for you
      Building a Java chat server
    LVL 30

    Assisted Solution

    LVL 92

    Expert Comment

    split em
    LVL 30

    Expert Comment

    Sounds fine to me.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    If you have upgraded to Java2 update 10 on a Microsoft Windows client, you may have discovered that your Java application does not work as it did before.  For example, the colors of your Java2D graphic may be all wrong for no apparent reason. Aft…
    For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now