Question

I'm trying to write a client server application. the clients post service requests and the server receives them and display them in a tech room.

everything was fine until I tried to send a screen capture to a special admin client, that should receive a screen capture of the list of live requests.

my main server listening thread looks like this :

while (true) {

         clientSocket = echoServer.accept();
         log.debug("Server Started Listening");
         is = new DataInputStream(clientSocket.getInputStream());
         os = new PrintStream(clientSocket.getOutputStream());

 // An option for a stop listening button. currently not available !
         if( listening==true )  {
         line = is.readUTF();
         os.println(line); 
         System.out.println(line);
         RequestReciever.pharseToRequest(line);
}

The pharseToRequest Method looks like this :

public static void pharseToRequest(String input) {

    List<String> list = new ArrayList<String>(Arrays.asList(input.split(";;;")));
    if (list.get(0).equalsIgnoreCase("Login") && list.get(1).equalsIgnoreCase("Login") && list.get(2).equalsIgnoreCase("5"))
    {
        _adminClients.add(list.get(4));
        updateScreenCapture();
        AdminClientUpdate tmp = new AdminClientUpdate(list.get(4));
        Thread aCU = new Thread (tmp);
        aCU.start();
    }
    else
    {
    ServerRequest newReq = new ServerRequest(list.get(0), list.get(1), Integer.parseInt(list.get(2)),list.get(3),list.get(4));
    addRequest(newReq);
    }
}

when the client sends "Login" as the data, I treat him as an ADMIN CLIENT, and try to send it a screencapture, via the AdminclientUpdate thread.

and when a client sent regular data, I just update it on the server screen with the "addRequest" method.

the problem I have is when I try to send the screen capture, it will find its way to the admin client and will be updated there correctly, but my server gets an error and stops working.

I suspect it might have something to do with the listening thread still have data in it from the old request while the AdminclientUpdate thread transferring data, or something.

This is the Error I get from the server , after sending the screen capture :

java.io.EOFException
    at java.io.DataInputStream.readUnsignedShort(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at ListeningThread.run(ListeningThread.java:50)
at java.lang.Thread.run(Unknown Source)

The serversocket.accept() continutes reading as is just received a new request from a client , when it really did not... instead of pausing and waiting for a new request...

I'm stuck with this for two weeks now, and very frustrated.

please HELP.

David.

Was it helpful?

Solution

In my case The server should start a new thread to handle every accepted connection, instead of processing each one in-line in the accept thread. But also I tried to get the first update via the serversocket instead of the login initialization. now, after getting the 1st update while logging in, I added a Server Socket on the client side so it will keep listening for further updates from server.

EJP's idea gave me the first lead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top