[1552] in java-interest

home help back first fref pref prev next nref lref last post

Re: Data streams and networking on Win95

daemon@ATHENA.MIT.EDU (Jonathan Payne)
Thu Sep 7 17:17:29 1995

Date: Thu, 7 Sep 1995 09:28:09 -0700
From: jpayne@starwave.com (Jonathan Payne)
To: ajg@brainiac.com
Cc: java-interest@java.Eng.Sun.COM

OK, your problem is that you never flushed the client connection
before closing the server.  It seems reasonable to me that you
shouldn't have to flush the connection, but apparently
client.closeServer() doesn't flush the connection.  I am not sure how
things work anymore, but it might have to do with buffered and not
buffered streams attached to the socket, and which one to flush, etc.
I think this is better in beta, but I am not sure.

So, anyway, your in.readInt() returned -1 because readInt itself got
a -1 (EOF) on the first character, and DataInputStream is not smart
enough to complain if it gets EOF while reading "binary data".  So it
silently returned -1.

This might also be a bug.

    Attached is a small test program that sends an int from a client to a 
    server. When run on a Windows 95 box the int is received by the server as 
    - -1 and not as the sent 12345. Given that network byte ordering is a well 
    known problem I must be missing something, but can't find it in the doc. 
    Any ideas? Thanks.

    (Are primative data types stored in the platform format? The VM guide does 
    not say. If this is so then the bit shifting done in the data stream 
    classes might be the cause of the problem.)

    - -- Andrew (ajg@brainiac.com)

    import net.*;
    import java.io.*;

    class Server extends NetworkServer {
	    public void serviceRequest() {
		    System.out.println( "servicing request" );
		    DataInputStream in = new DataInputStream( clientInput );
		    int i = in.readInt();
		    System.out.println( i );
    //		String s = in.readUTF();
    //		System.out.println( s.length() );
    //		System.out.println( s );
		    System.out.flush();
	    }
    }

    class Main {
	    public static void main( String args[] ) {
		    Server server = new Server();
		    server.startServer( 4000 );
		    NetworkClient client = new NetworkClient();
		    client.openServer( "edgework", 4000 );
		    DataOutputStream out = new DataOutputStream( client.serverOutput );
		    out.writeInt( 12345 );
    //		out.writeUTF( "Hello World" );
		    client.closeServer();
	    }
    }
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post