Hello,
I'm currently using a ServerSocket. Here is my code reduced to the simple core:
ServerSocket ss = new ServerSocket(port, backlog);
Socket connectedSocket = ss.accept();
InputStream inputStream = ss.getInputStream();
int c = -1;
while (true)
{
while ((c=inputStream.read()) != -1)
{
System.out.println((char) c);
}
}
On the client side I use a Socket to connect to this ServerSocket and try to
send data multiple times after 2 seconds of delay:
Socket s = new Socket(remoteipaddr, remoteport);
OutputStream os = s.getOutputStream();
for (int i=1; i<4; i++)
{
os.write(i + " Hello Server!".getBytes());
os.flush();
// I don't want to close the stream
//os.close
Thread.sleep(2000);
}
At the server's side nothing is received! When I close the Outputstream at the client's side, the data is sent. The problem: I would have to reconnect every time to get a new Socket object and write the next part of data (3 times in the above example).
Isn't it possible to connect to the ServerSocket just once and then have the client write as much data as I want to and have it immediately received (and printed to console) by the server?