Re: Client Server socket behavior on XP different for 127.0.0.1

From: Steve Horsley (shoot_at_the.moon)
Date: 09/01/04


Date: Wed, 01 Sep 2004 22:57:03 +0100

Tim wrote:
> I have two java applications, one a client, the other a server.
>
> The cient connects to the server and then they start transmitting data
> back and forth.
>
> If I run the server on Lunix/Unix, connecting via a remote client is
> not a problem. However, if I am running the server on Windows XP, it
> appears that the first string sent from the server to the client that
> is not terminated with a \n causes both the client and the server to
> Exception out on their respective sockets. This takes several minutes
> and actually hoses network access on the XP mashine, requiring a
> reboot to regain net access.
>
> If I start the client up on the same machine as the server (still
> using XP) and connect via 127.0.01 instead of the actual IP address,
> evertyhing works just fine.
>
> I have checked to ensure that there is no firewalling going on, and
> this behaviour has been observed on more than one XP machine.
>
> Any help would be appreciated.
>
> Thanks,
> Tim
>
> Client connects rather simply.
>
> sckConnection = new Sockect(address, port);
> stmOut = new DataOutputStream(sckConnection.getOutputStream();
> stmIn = new BufferedReader(new
> InputStreamReader(sckConnection.getInputStream()));
>
> stmOut.writeBytes("data\n");
>
> Server also uses DataOutputStream and BufferedReader.
> Server sends commands like the following:
> stmOut.writeBytes(""+(char)3+"client message\n");
> stmOut.writeBytes(""+(char)14);
>
> I get 3 messages of the first type sent to the client (along with
> responses sent back to the server) but the 14 doesn't seem to make it.
>
> Client does the following to process input:
> while (incoming != -1)
> {
> incoming = stmIn.read();
> switch (incoming)
> {
> case 3:
> addText(stmIn.readLine()+"\n");
> case 14:
> blnLoaded = true;
> }
> }

Any data sensitivity is due entirely to your code - not the TCP stack.

Firstly, you are probably using different character set conversions
between the sender and the receiver, because DataOutputStream.writeBytes()
just takes the lower 8 bits of the character (effectively using ISO8859-1
encoding), but new InputStreamReader(InputStream) creats a Reader that uses
the platform default characterset encoding. So you cannot at the moment
be sure that the characters you send are the characters you receive.
It may be that your (char)14 is being converted to a questionmark.

Secondly, beware that TCP does not respect message boundaries - it can
split or concatenate chunks of data that are sent in separate write()
calls. This splitting and concatenating is affected by network
timing, so may behave differently locally to the same machine than
over a network. If you assume that a read() will always get exactly
what one write() sent, you will eventually go wrong.
You seem to be using explicit message boundaries here
(using '\n', '\r' or "\r\n" as the separator), but bear this
in mind for the future.

Thirdly, if you use a buffered writer, remember to call flush() at
the end.

I don't know why you would get an exception - there is nothing in
the code you posted that ever closes the connection.

I don't know why using the loopback address should change behaviour.

Steve



Relevant Pages

  • Re: How do I stop a Winsock from buffering characters?
    ... from the client code and have the server see it right away. ... I don't see the server reads that you're talking about as having dropped ... first character of the client send. ... public delegate int MessageFn(long MessageType, ...
    (microsoft.public.windowsce.embedded)
  • Re: What doesnt lend itself to OO?
    ... >> proxy and instructs the server to constuct the real object. ... rather than client code. ... If 'clock' is instantiated in the server, ... > for the server interface at the OOA level. ...
    (comp.object)
  • Re: How do I stop a Winsock from buffering characters?
    ... Windows CE side and receive ASCII on the server side. ... Unicode characters will be 0x00xy where xy makes up the ASCII character, ... I have two apps one is a Winsock Client as in the following: ... public delegate int MessageFn(long MessageType, ...
    (microsoft.public.windowsce.embedded)
  • This is going straight to the pool room
    ... or not the client has privilege to do what they're trying to do, ... The server environment is this: ... 3GL User action Routines that Tier3 will execute on your behalf during the ... Routine Name: USER_INIT ...
    (comp.os.vms)
  • Re: How do I stop a Winsock from buffering characters?
    ... The client is just doing this to send: ... Stream s = client.GetStream; ... I just wan to send one character ... from the client code and have the server see it right away. ...
    (microsoft.public.windowsce.embedded)