Reputation: 11356
i am trying to get an android app to send tcp data to a server on my network. The server was written in c#.
When i use the code below to transmit data, the server only receives a whole series of \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0.
Does anyone know why?
Socket socket = new Socket(host, port);
PrintWriter pw = new PrintWriter(socket.getOutputStream(), true);
pw.print("test");
socket.close();
Upvotes: 2
Views: 2261
Reputation: 3284
you may want to try println("test"). In java you need to flush the line, so that may be the cause of your issues.
Upvotes: 0
Reputation: 8941
I'm not sure if this has anything to do with it, but you might want to try manually flushing the PrintWriter
. You did pass true
to its constructor to request autoflushing, but I believe this only occurs when you print a newline character, which your sample code doesn't do.
Upvotes: 2