0

I am using the Java Websockets library from https://github.com/TooTallNate/Java-WebSocket. I would like to calculate the latency between sending messages. When using the send(message); function, will that wait until the server receives the packet (since it uses TCP), or does it just finish the method in it's own thread.

Thanks!

Ajay
  • 437
  • 7
  • 22
  • Did you try anything? What did you find? – Jim Garrison Jan 08 '17 at 23:00
  • @Jim Garrison, well I have googled, and looked at the source. But could not find a definite answer. – Ajay Jan 08 '17 at 23:02
  • It should be pretty easy to step through the code and figure this out. Since the library is implemented using NIO, I would expect it to provide both options. – Jim Garrison Jan 08 '17 at 23:03
  • @JimGarrison I have and see no proof of it not waiting, but would like to confirm it with someone who knows for sure. – Ajay Jan 08 '17 at 23:06

2 Answers2

2

When using the send(message); function, will that wait until the server receives the method

That statement doesn't even make sense. The server doesn't receive the method, it receives the data the method sends.

(since it uses TCP)

There is nothing in the TCP API that waits for the peer to receive anything. When you send data via TCP, it is buffered in the local socket send buffer and returns immediately. The actual data is sent to the peer asynchronously over the network. The send blocks while the send buffer is full if the underlying socket is in blocking mode (the default), otherwise it either returns a short send return code in non-blocking mode, or posts a Future of some kind in asynchronous mode. Your question may really be about which of these modes the underlying socket is in, or not.

or does it just finish the method in its own thread.

It always does that in any of the modes.

user207421
  • 305,947
  • 44
  • 307
  • 483
0

Turns out it is a

non-blocking event-driven model (similar to the WebSocket API for web browsers).

This is found from the README.MD here: https://github.com/TooTallNate/Java-WebSocket

Ajay
  • 437
  • 7
  • 22