Re: Client Server socket behavior on XP different for 127.0.0.1
From: Steve Horsley (shoot_at_the.moon)
Date: 09/01/04
- Next message: Sudsy: "Re: Bah. Struts problem. Validation -- or lack thereof."
- Previous message: Steve Horsley: "Re: Thread synchronization"
- Next in thread: Tim: "Re: Client Server socket behavior on XP different for 127.0.0.1"
- Reply: Tim: "Re: Client Server socket behavior on XP different for 127.0.0.1"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Sudsy: "Re: Bah. Struts problem. Validation -- or lack thereof."
- Previous message: Steve Horsley: "Re: Thread synchronization"
- Next in thread: Tim: "Re: Client Server socket behavior on XP different for 127.0.0.1"
- Reply: Tim: "Re: Client Server socket behavior on XP different for 127.0.0.1"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|