I have initialize a socket and made a connection between my simple client application and server application.
In a thread in my server application I have this line:
out = new BufferedOutputStream(socket.getOutputStream());
Then I send some data to my client and then I close the BufferedOutputStream with
out.close();
After that I restart the thread and then this line of code is beeing run again:
out = new BufferedOutputStream(socket.getOutputStream());
The problem is that the socket gets closed down when I run the thread for the second time. I have no clue why.
I have checked the socket state with System.out.println(socket.isConnected()); and it returns true both the times, so the socket is not closed what I can see.
Why does my socket close down when redeclaring the BufferedOutputStream?
Another question:
When I send the byte array "myByteArray" with:
out.write(myByteArray);
my client is getting all the bytes (I print all of them).
But when I just send one byte:
out.write(-10);
my client is not getting that byte.
How come?