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 implemented socket read into a separeted thread:

public class Cititor implements Runnable{

    private Socket skt ;
    private BufferedReader in;
    private PrintWriter out ;
    private Boolean connected ;
    private javax.swing.JTextArea afis;

    public Cititor(Socket skt, 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 din
socket!");
                    }
                }
            } 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to