0

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.

2
  • Your server should start a new thread to handle every accepted connection, instead of processing each one in-line in the accept thread.
    – user207421
    Feb 10, 2014 at 20:43
  • I have managed to fix some of the problem by doing so. everything works fine on the first client login. now i'm looking for a way to initialize updates from the server, when there is a change, to the client. do I have to add a serversocket on the client too in order to do so ? or is there any other , more elegant wayu to do so ? Feb 11, 2014 at 9:42

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.