Creating multiple TCP Socket connections RRS feed

  • Question

  • In one of my parsing program i have to do the following(in C,C++,VC++):-

    I have to connect 100 machines(dialysis machines) through socket programming. Send request to each machine and receive the response from the machine and the data that i will get from the machine i will have to parse that data and write the values in the a file.I have to send the request to each machine after every 5seconds.

    So to accomplish the above task i am thinking to do it as:-

    I will read the ip and port of each machine from the data base,make a thread to connect to each machine and in each thread a sub thread(child thread) will be made which will send and receive and parse the data from the machine after every 5 second(and write the values in a txt file). My parsing function will be common.

    Is it the feasible solution. Please help me.Thnaks in advance.


    • Moved by Jesse Jiang Thursday, September 27, 2012 8:31 AM (From:Visual C++ General)
    Tuesday, September 18, 2012 7:02 AM

All replies

  • be careful about creating a lot of thread for each connection. thread is expensive.

    consider using PPL or Actor in your case

    Tuesday, September 18, 2012 8:35 AM
  • Assuming there is only one network card, creating 200 threads to use it is very inefficient and will reduce performance and add complexity for interthread communication.

    If you use non-blocking sockets you can do it all in one thread. Or maybe two threads: one for communication and one for file writing.


    • Proposed as answer by i1friend Thursday, September 20, 2012 6:44 AM
    Tuesday, September 18, 2012 1:35 PM
  • Can u please give me sample code?


    Monday, September 24, 2012 11:20 AM
  • Hi,

    Welcome to the MSDN forum.
    Based on your description, your problems is about Winsock, I’d move the thread to Windows Desktop Winsock Kernel (WSK) ,since we here only discuss general native C++ problems on developing.
    Thanks for your understanding.

    Elegentin Xie [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, September 27, 2012 8:32 AM