solved, i wasn't sending end of lines from the server. and i used readline in the client. :)
On Sep 11, 2:13 pm, "Fiveholiday" <fiveholida...@hotmail.com> wrote: > It is not always possible for servers to report anything to the clients, > unless ofcourse, the client is connected to the server. The only way that > could happen is if the client doubles as a server too, that way, it gets > notifications from other clients. > > Or maybe I didn't get yourquestioncorrectly - > Again we'd need the C++ code to see where you're going wrong. > > -- > Evans > > ----- Original Message ----- > From: "ioan-eugen stan" <stan.ieu...@gmail.com> > To: "Java EE (J2EE) Programming with Passion!" > > <java-ee-j2ee-programming-with-passion@googlegroups.com> > Sent: Friday, September 11, 2009 10:13 AM > Subject: [java ee programming] javasocketquestion > > Hello, > > I'm writing a c++ server and a java client that connects to it. The > client connects to the server (TCP), sends a message and gets a echo > reply every time, so the two can speak freely. But i'm puzzeled > because > I want the server to send data to the client when an event happens (I > push a button on the server). When te event occurs the server sends > the > string, but the client does't receive it until it does a send/receive > reply when it receives both the event string and the echo string. > > I implementedsocketread into a separeted thread: > > public class Cititor implements Runnable{ > > privateSocketskt ; > private BufferedReader in; > private PrintWriter out ; > private Boolean connected ; > private javax.swing.JTextArea afis; > > public Cititor(Socketskt, BufferedReader in, PrintWriter out, > Boolean connected, JTextArea afis) { > this.skt = skt; > this.in = in; > this.out = out; > this.connected = connected; > this.afis = afis; > } > > public void run(){ > System.out.println("să citim mesajele " + connected); > String inputLine = new String(""), outputLine; > > do { > try { > > Thread.sleep(100); > > if (connected) { > try { > //out.print(" "); > out.flush(); > inputLine = in.readLine(); > if (!inputLine.equals(" ")) > afis.append(inputLine + "\n"); > System.out.println(inputLine); > } catch (IOException e) { > System.err.println("Excepție citire dinsocket!"); > } > } > } catch (InterruptedException ex) { > Logger.getLogger(Chat.class.getName()).log > (Level.SEVERE, > null, ex); > } > }while (inputLine.equals("pa!") == false) ; > > } > > In the main class init method I have this: > > myCititor = new Cititor(skt,in,out,connected,afisare); > Thread t = new Thread ( myCititor); > t.start(); > > And to send messages to the server I push a button: > > private void trimiteActionPerformed(java.awt.event.ActionEvent evt) > { > if (connected) > out.println(textTrimite.getText()); > else > System.out.println("No connection"); > } > > The server uses a switch statement with FD_READ,FD_ACCEPT and FD_CLOSE > (processing WSAGETSELECT event -> WsAsync), and sends when a button is > pushed (I'm using windows events button clicked). > > The trying to make the server capable of informing the client when an > event occurs. The server is used for monitoring certain activities. > But > the client does't receive unless it sends and waits for a reply. > What am I doing wrong? > > Regards, > -- stan ioan-eugen --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Java EE (J2EE) Programming with Passion!" group. To post to this group, send email to java-ee-j2ee-programming-with-passion@googlegroups.com To unsubscribe from this group, send email to java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en -~----------~----~----~----~------~----~------~--~---