Re: Java Socket Communication: Works under windows, times out under Linux and Mac OS
Stetson wrote:
On Mar 13, 5:22??am, Nigel Wade <n...@ion.le.ac.uk> wrote:
Stetson wrote:
Found the source of this 'initiation' character in the manufacturer's
code:
?? ?? ?? ?? ?? ?? ?? // b Z [ W ???
?? ?? ?? ?? ?? ?? ?? String msg = String.valueOf((char)0x05);
?? ?? ?? ?? ?? ?? ?? msg += device + data;
?? ?? ?? ?? ?? ?? ?? msg = addBcc(msg);
?? ?? ?? ?? ?? ?? ?? // b Z [ W M
?? ?? ?? ?? ?? ?? ?? send(msg);
I think that 'String.valueOf((char)0x05); is being interpreted
differently in different OSes, but I don't know why that would be.
If what you are sending is essential binary I don't think you should use
Writer/Readers. They are for I/O of encoded character strings. Use a Stream
instead (for both reading and writing).
The reason the behaviour varies between OS could be due to differing default
character encodings. It may well be that what you think you are sending to
the
server is not what is actually emerging from the Writer.
If you want to see what's going out on the wire, and what is returned, try
installing WireShark. It's about the best software network diagnostic tool
you
can get for free.
--
Nigel Wade
I've forced the system, outputstreamwriter, and input stream writer to
use Cp1252 encoding (This is the default on Windows and is what the
server seems to understand), but I still get a null return when
running from OSX:
run:
System File Encoding: Cp1252
OutputStreamWriter Encoding: Cp1252
InputStreamWriter Encoding: Cp1252
send: FF0RD00400423
Read input stream for data
00000000000000000000
I do very little character/string I/O using Reader/Writers. Does the difference
in line terminator between Linux/OSX and Windows cause any problem when using
readLine()?
I'll try WireShark to see if I can get a better picture of what's
really going on at a lower level, thanks for the tip!
It's one of my main diagnostic tools for networking problems.
Ping/traceroute/netstat and then WireShark. There's not much can beat being
able to watch (and examine) the packets flowing between the client/server.
--
Nigel Wade