2

I can find any documentatin anywhere and would like to know what would be the best method of send multiple messages as fast as possible.

for example if I had 300 devices recieivng messages from one server would it be better to send out one big message and have the devices pick out the parts that they need or send 300 messages but at 1/300 of the size. They would only be small stings so the 300 devies would only be getting 6 bytes each

Does it make a difference?

Thanks in advanced.

NickREd
  • 51
  • 3
  • 1
    When you say "one big message", with TCP you'd need to send that "one big message" to *each* device individually. You can't broadcast messages when using TCP (but you can with UDP). – Greg Hewgill Mar 11 '12 at 01:09

1 Answers1

1

If the socket's Nagle algorithm is enabled, then sending multiple smaller messages over a given connection will generally be slower than sending fewer larger messages over that same connection. Nagle buffers outbound data internally and has to wait for enough data to be buffered and/or timed out so it can send efficient messages. For general socket usage, having Nagle enabled is usually preferred as it offers a good balance between speed, performance, and overhead that is acceptable to most apps. But if you need to send time-sensitive messages then you usually have to disable Nagle so every message is transmitted individually as soon as possible.

What you describe about sending a single message to multiple devices is not possible with TCP, though. Presumably the devices each have their own TCP connection directly with the server. To send a single message to all 300 connections, you would have to make 300 independant copies of the message, one to each connection. TCP has no broadcasting capabilities (switch to UDP or Multicasting if you need that). The only way to send a single server message and have 300 devices respond to it is if the devices are not connecting to the server directly, but instead are communicating through a proxy that maintains a single connection to the server and forwards received server messages to each device as needed.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • it sounds like he has 300 connections but wants to broadcast the data on all connections vs individual messages unique to each connection. This sounds nonsensical to me since you would be multiplying the data sent by an order of magnitude! – fido Mar 11 '12 at 01:24
  • I was thinking of broadcasting. I thought you could do it with TCP but I guess I have to look into UDP if I dont send individual messages. I want the messages to be received as fast as possibly so that every can receive messages in almost realt time without too much of a delay – NickREd Mar 11 '12 at 13:35