#Problem of tcp communication between rust server and java client
27 messages · Page 1 of 1 (latest)
Hi, I have a problem:
I'm trying to make an application in 2 parts : a rust server and a java client that have to communicate with each other, I can make the communication from java to rust, but not the other way around, I don't have any error or log, it just doesn't work.
I don't know from which side the problem comes
use write_all instead of write
It doesn't seem to work ...
it's possible that the problem comes from java
I tried that too and no
What if you close the writing end of the TCP stream? (after writing the data)
No, binding to 0.0.0.0 is correct
127.0.0.1 will only allow connections from the same machine I think
I try and answer you
that is: ```rs
writer.get_ref().shutdown(net::Shutdown::Write).unwrap();
makes sense
and the server writes well
idk Java well enough to really understand what it’s doing
ok, thanks anyway, I'll go ask elsewhere
if someone else has an answer, I would appreciate it 😄
please ping me to answer
@viral cape
writer.write_all(b"test\0");
your problem is a java problem, not a rust problem
I think readUTF expects a 16 bit length to precede the string
also, despite the name, readUTF does not use utf8 encoding like rust does
it uses some really crazy encoding where 0 is encoded with two bytes, and the encoded values aren't unicode scalars but rather utf16 codepoints, which are decoded again to get the actual string; that is, surrogate pairs are encoded as two values instead of one like actual utf8 does
oh, you had writeUTF but not readUTF. Well, the crazy encoding rules still apply. and who knows what DataInputStream does. But the rust code is sane, it's still the java side which is not just reading bytes