I have a problem with some socket (server) code but
don't know whether its the code, improper use of sockets,
or the java implementation for linux. The server sends
2 bytes to the client and the client reads them. Then the
client sends a byte to the server and the server reads it. 
The problem is that after the server reads its byte, it cannot
then send the client two bytes. The client is written in perl.
What am I missing....??



public static void main(String args[]) {

        byte inString;
        ServerSocket    serversocket    = null;
        Socket  clientsocket = null;
        DataOutputStream clientsocket_out = null;
        DataInputStream         clientsocket_in = null;

        try {
                serversocket = new ServerSocket(4554);
        } catch (IOException e) {
        }                                     


        try {
                clientsocket = serversocket.accept();

                clientsocket_in  = new DataInputStream
                (clientsocket.getInputStream());
                clientsocket_out = new DataOutputStream
                (clientsocket.getOutputStream());

                //  WORKS, CLIENT READS 2 BYTES ("OK")
                clientsocket_out.writeBytes("OK");

                //  WORKS, CLIENT SENDS 1 BYTE AND SERVER
                //  GETS IT
                inString = clientsocket_in.readByte();

                //  THIS FAILS, HANGING SERVER AND CLIENT
                //  CLIENT CANNOT READ THIS BYTE
                //  try writing again to client a second time
                clientsocket_out.writeBytes("PP"); 

        } catch (IOException e) {
        }                                                
}


Thanks,

Mark

Reply via email to