3

What is the best way to know if a message has arrived on client? I'm using a BufferedWriter to send a message and it sends away the message. I could use an answer from the client and read it on the server, but I would like something faster

Socket socket = MainServer.map_socket.get(person);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
bw.write(msg_date +  " " + mittente + " " + testo);
bw.newLine();
bw.flush();

I'm using this code to send messages from server. It retrieve the socket from a map using a key, the problem is when the client closes the connection and Bufferedwriter sends the message (and obviously it doesn't arrive to the client).

Sled
  • 18,541
  • 27
  • 119
  • 168

1 Answers1

1

The only way for the server to know the client received something is for the client to tell the server it has received something. This acknowledgement mechanism should be part of your application protocol.

Dev
  • 11,919
  • 3
  • 40
  • 53
  • there's no other way? –  Oct 23 '13 at 17:49
  • 1
    You can wait for other answers, but generally no. You need to build something in to your application protocol if the server requires acknowledgement that the client received the message. – Dev Oct 23 '13 at 17:51
  • Assuming TCP, there won't be any other answers - it IS the only way. – Martin James Oct 24 '13 at 11:32