CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2018
    Posts
    158

    send message to multiple clients at the same time

    In C if I have to send a message to 12 server of the same network (of course I know both IP and port) by tcp connection at the same time using socket programming, how can I make it ?
    I though to use for from 0 to 11 but in this way requests would be sent in serial mode and not at the same time.
    What solution do you suggest me ?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: send message to multiple clients at the same time

    1. Why is it som important for you to "send at the same time"?
    2. If you don't care about whether your message was received or not (just send and forget) then you can use the broadcast (datagram socket).
    Victor Nijegorodov

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: send message to multiple clients at the same time

    Well unless you're into trading where nanoseconds count, issuing 12 messages serially (unless each message is substantial in size) will be received almost at the 'same time' with no discernable difference. Note that only 1 network packet at a time can travel over a network between 2 points. If you really want to consecutively (why?) send 12 messages from one device then have 12 network connections - one to each of the other devices. The other way as mentioned by Victor as 2 ) above is to issue one broadcast message (any device on the network can receive it).
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    Join Date
    May 2018
    Posts
    158

    Re: send message to multiple clients at the same time

    Thanks, I'll give a lot of importance to your suggestions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured