Multiple connections to devices using Sockets [closed]

1

I have a method that connects to a card reader via TCP / IP (ip, port) using Sockets. For the 1: 1 connection is working, but now I need to connect to more than one device simultaneously. Would I have to create a Thread for each connection, or would I have another way to do this? Remembering that my system is a "client" of the readers.

    
asked by anonymous 16.08.2016 / 21:11

2 answers

0

This depends on the methods you are using to connect, send, and receive data.

If you are using for example the methods Connect , Send and Receive they block the execution then it would be necessary to use Threads, however this is not the most recommended, it is recommended to use the asynchronous methods.

Using the BeginConnect , BeginSend , and BeginReceive methods you should have no problems since they do not block the thread and use a Callback system to notify you when they have finished executing or receiving data.

    
16.08.2016 / 21:47
0

Dear JcSaint,

A socket implementation is not such a simple task, even with the various abstractions that .NET offers.

It is possible to start a new thread per connection but this is not the recommended method because if there is overload the operating system will probably kill your process.

In a web server that I developed using C ++ I used the asynchronous approach, using 1 thread to receive new connections and a pool of connections which is processed by the other physical threads available on the hardware (so I got better performance for my case), these being duly synchronized when necessary.

I hope I have helped.

    
16.08.2016 / 22:07