client - Server not recieving message - Java -


i have server , client in server ui, have 3 jlabel using mouseclick communicate indiviual clients connected server. when click on jlabel1 messsage going client1 when client1 recieves message should respond not responding server when recieves message it. hope guide me whats wrong code.

//server

void connect_clients()     {         try {             serversocket listener = new serversocket(7700);             jbutton1.settext("server running!");             jbutton1.setenabled(false);                 while (true) {                      socket = listener.accept();                     socketlist.add(socket);               //recieve method client come here.                  }              }         catch(ioexception ex)         {             joptionpane.showmessagedialog(null, "5"+ex);         }     }  *******here when click jlabel1,message goign 1st client ,it should respond on seeing message client. not.****     private void jlabel1mouseclicked(java.awt.event.mouseevent evt) {                                           printwriter out;      try {          socket = socketlist.get(0);          //joptionpane.showmessagedialog(null, socket);          out = new printwriter(socket.getoutputstream(), true);          out.println("pc 1");       } catch (ioexception ex) {      joptionpane.showmessagedialog(null, "1"+ex);} 

//client

void connect_server() throws ioexception     {         try {             // todo code application logic here             string serveraddress = joptionpane.showinputdialog(                     "enter ip address of machine is\n" +                             "running date service on port 9090:");             s = new socket(serveraddress, 7700);              while(true){                 bufferedreader input =             new bufferedreader(new inputstreamreader(s.getinputstream()));             string answer = input.readline();             system.out.println(answer);                 if(answer != null)                 {                      //respond method server come here.                     joptionpane.showmessagedialog(null,"answer not null");                }              }            } 

you must create bufferedreader outside loop; in fact @ same time socket. , if readline() returns null should close it.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -