>I am working on an app that connects to a device using the TCP protocol. I send a data packet (containing a command), this is a relatively small data packet. Then the device that I am connected to will return a data packet (again relatively small packet up to 1K worth of data).
>I will connect to the device up to 250 times (send and receive data) then I will wait for about 1 minute (might be a longer wait. I think I will make the waiting period programmable from 30 seconds to 5 minutes) and do the same thing over again.
>
>Currently what I am doing is connecting to the IP endpoint (IP address and port) using TCP anding the command, then receiving the data then disconnecting. Then I connect, send, receive and disconnect again and so on and so forth.
>
>This is in my oppinion the correct way of doing this.
>
>The other option is to connect, then send command#1, receive, send command #2, receive, ....send command#250, receive and then disconnect
>
>Any thoughts on the issue? Has anyone created a class that does something similar? Which method would you choose?
>
>Thanks,
>Einar
I haven't worked at this "low-level", but you might consider whether TCP is more appropriate, or rather, UDP.
TCP has additional overhead, because it has built-in mechanisms to ensure delivery: if a packet is not received, it will be sent again.
UDP does not have this additional overhead, but you have to control yourself whether the data arrived. But it seems you are doing something similar anyway.
UDP is sometimes used to transfer small amounts of data, or when quick delivery is more important than flawless data transfer - as in the case of voice over IP.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)