1

I am very new to Socket programming, and I would appreciate any input you have in my question.

I am a physicist working on a project where the time intervals and coincidence of measurements play a big role. I have multiple measurement units connected to my laptop through Ethernet. The measurement units have a Linux kernel running with fortunately a Telnet server.

I implemented a scheme where the measurements are send to the laptop, to a specific port by all the units, and from the laptop the calculations are done. Each unit also get a response which request them to adjust parameters with respect to the calculations.
Currently I am running this setup with a 1s interval. Which would allow me to do receive data and apply corrections, from all the units in a reasonable manner.

But I would like to make all these measurements coinciding (currently it is a while loop which checks everything one by one), and also scalable. I am thinking of using threading to accomplish this. But I have no idea how to sync them, or prevent errors like "this port is already bound". Is using multi-threading a good way? Or should I use any other approach?

I am using C and socket library to implement this.

TLDR : Multiple measurement unit are connected to the same port. I need to receive and respond to the units at the same time.

6
  • 1
    Any data is received sequentially. No matter how many threads you use, they will not receive the packets at the same time.
    – Gerhardh
    Commented Jul 1 at 15:29
  • @Gerhardh Yes Makes sense. Is there any common method used for these kind of situations? which I can use as a reference and improve my code. Commented Jul 1 at 15:34
  • 1
    You might benefit from use of Time Sensitive Networking en.wikipedia.org/wiki/Time-Sensitive_Networking These protocols allow you to schedule messages within packet subframes at the millisecond timing level.
    – Jim Rogers
    Commented Jul 1 at 15:39
  • You have no reasonable hope of "at the same time" in any case. You need to be looking at something more like within the same time interval. Re-framing the problem in such terms will probably help you design or discover appropriate approaches, and it will definitely help you reason about what will and what will not meet your requirements. Commented Jul 1 at 15:55
  • 5
    You should let each independent "measurement unit" to use its own, local clock to schedule the intended time of each measurement and, to record the actual time of each. Make sure that all of the clocks are closely synchronized (by configuring network time protocol, which should be built in to Linux), and send all of the "actual" timestamps back to the central computer along with the measurements, and you should have everything you need to achieve your goal. Commented Jul 1 at 16:20

0

Browse other questions tagged or ask your own question.