udp multicast server and client

Discussion in 'C Programming' started by skpopu@gmail.com, Apr 25, 2008.

  1. Guest

    I have a two systems and I am able to communicate both systems using
    udp server and client at both ends but I need to make one system as
    concurrent server and now I would like to add one more system into the
    group and now I would like to multicast the message from My main
    server to the new joined system and now I should be able to send and
    recieve from both the other systems to the main server.
    Exactly what I have with me is : Two systems having udp server and
    client programs running in each of the systems and they are
    communicating well.
    Now what I need is I am adding one more system to my network and I
    should be able to serve the other system also from One of this
    systems.For this I have made One thread as listener thread and every
    time a new client comes for service it is seperated as new thread. But
    I facing the problem here recvfrom() got blocked. I need any one of ur
    help. Please Note that I am using only UDP sock streams not TCP.Thanks
    for helping me.
     
    , Apr 25, 2008
    #1
    1. Advertisements

  2. Ian Collins Guest

    wrote:
    > Now what I need is I am adding one more system to my network and I
    > should be able to serve the other system also from One of this
    > systems.For this I have made One thread as listener thread and every
    > time a new client comes for service it is seperated as new thread. But
    > I facing the problem here recvfrom() got blocked. I need any one of ur
    > help. Please Note that I am using only UDP sock streams not TCP.Thanks
    > for helping me.


    You probably should ask on comp.unix.programmer (or a winsock
    equivalent). As Richard just said, your situation is not uncommon,
    similar question often pop up on c.u.p.

    As an aside, using blocking sockets with threads is common. Also you
    can't reliably stream over UDP without a using higher level protocol to
    do the work usually done by TCP.

    --
    Ian Collins.
     
    Ian Collins, Apr 25, 2008
    #2
    1. Advertisements

  3. On 25 Apr 2008 at 4:30, Richard Heathfield wrote:
    > said:
    >> But I facing the problem here recvfrom() got blocked.

    >
    > Look long and hard at select().


    Good advice. Perhaps a short piece of example code will be helpful to
    the OP.


    #include <sys/select.h>

    ....

    /* set up your socket with file descriptor fd */

    ....

    int r;
    fd_set rfds;
    struct timeval tv;

    FD_ZERO(&rfds);
    FD_SET(fd, &rfds);

    tv.tv_sec = 30;
    tv.tv_usec = 0; /* timeout after 30 secs plus 0 ms */

    r=select(fd+1, &rfds, NULL, NULL, &tv);

    if (r<0) {
    /* deal with error */
    } else if (r==0) {
    /* deal with timeout */
    } else {
    recvfrom(fd, ...);
    ...
    }
     
    Antoninus Twink, Apr 25, 2008
    #3
  4. On Apr 25, 9:30 am, Richard Heathfield <> wrote:
    > said:
    >
    > > I have a two systems and I am able to communicate both systems using
    > > udp server and client at both ends

    >
    > If you have a client-server networking architecture, you'd almost certainly
    > be better off with TCP.
    >
    > <snip>
    >
    > > Now what I need is I am adding one more system to my network and I
    > > should be able to serve the other system also from One of this
    > > systems.For this I have made One thread as listener thread and every
    > > time a new client comes for service it is seperated as new thread.

    >
    > That is a very common design, but not one that I consider to be very wise.
    > When there are many clients, it over-uses thread resources, and under-uses
    > everything else. Having said that, it sounds like you only want to have a
    > very, very tiny network, so perhaps in your case it doesn't matter.
    >
    > > But
    > > I facing the problem here recvfrom() got blocked.

    >
    > Look long and hard at select(), which is not a standard C function.


    http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html#select
    hope this is helpful.
     
    Sri Harsha Dandibhotla, Apr 25, 2008
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    7
    Views:
    730
    CBFalconer
    Dec 1, 2006
  2. Replies:
    0
    Views:
    454
  3. inorlando
    Replies:
    3
    Views:
    1,415
    castironpi
    Aug 29, 2008
  4. neilsolent

    UDP Multicast Question

    neilsolent, Jan 21, 2009, in forum: Java
    Replies:
    2
    Views:
    796
    neilsolent
    Jan 22, 2009
  5. Gary C
    Replies:
    2
    Views:
    2,467
    Jorgen Grahn
    May 19, 2010
Loading...

Share This Page