• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

cleint server chat

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(System.in));
      try {
         strdata=br.readLine();
      } catch (IOException ioe) {
         System.out.println("IO error trying to read your name!");
      }
         
                     Socket s = null;
            try{
                  int serverPort = 7896;
                  s = new Socket("localhost",serverPort);
                  s.setKeepAlive(true);
                  DataInputStream in = new DataInputStream(s.getInputStream());
                  DataOutputStream out = new DataOutputStream(s.getOutputStream());
                  out.writeUTF(strdata);
                  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());}
            finally{
                  if(s!=null)
                  try{
                        s.close();
                        }
                  catch(IOException e){
                        System.out.println("close:"+e.getMessage());
                  }


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 ??

http://www.shoppinp.com/clientserver.rar
see this code
0
bob20062006
Asked:
bob20062006
  • 2
  • 2
3 Solutions
 
objectsCommented:
0
 
hoomanvCommented:
> 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
  http://www.cn-java.com/download/data/book/socket_chat.pdf
0
 
Mayank SAssociate Director - Product EngineeringCommented:
0
 
objectsCommented:
split em
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Sounds fine to me.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now