UDP data transfer hangs on recvfrom

Discussion in 'C++' started by Jack, Feb 1, 2007.

  1. Jack

    Jack Guest

    Hi guys,
    I can't figure this out.

    rec = recvfrom(sdUDP, buf, BUFSIZE, 0, (struct sockaddr
    *)&connectChannel, &chanSizeUDP );
    while(1){
    if (rec > 0){
    snt = sendto(sdUDP, buf, rec, 0, (struct sockaddr
    *)&connectChannel, chanSizeUDP );
    rec = recvfrom(sdUDP, buf, BUFSIZE, 0, (struct sockaddr
    *)&connectChannel, &chanSizeUDP );
    }
    else{
    stats();
    exit(0);
    }
    }

    The above is the code from a UDP server. The server is suppose to
    simply read the incoming data from the buffer and echo it back to the
    client. For some reason the code hangs on the recvfrom inside the
    while loop. I don't know why this happens... The client sends and
    receives the data but the server never exits.

    Any ideas..
    Jack, Feb 1, 2007
    #1
    1. Advertising

  2. Jack schrieb:
    > Hi guys,
    > I can't figure this out.

    [...socket stuff...]
    > The above is the code from a UDP server. The server is suppose to
    > simply read the incoming data from the buffer and echo it back to the
    > client. For some reason the code hangs on the recvfrom inside the
    > while loop. I don't know why this happens... The client sends and
    > receives the data but the server never exits.


    Read here:
    http://www.parashift.com/c -faq-lite/how-to-post.html#faq-5.9

    --
    Thomas
    http://www.netmeister.org/news/learn2quote.html
    Thomas J. Gritzan, Feb 1, 2007
    #2
    1. Advertising

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. Michael Bacarella

    httplib hangs in read / strace says recvfrom()

    Michael Bacarella, Sep 14, 2007, in forum: Python
    Replies:
    0
    Views:
    672
    Michael Bacarella
    Sep 14, 2007
  2. lgwe
    Replies:
    2
    Views:
    245
    Mark T
    Nov 4, 2007
  3. Lars Uffmann
    Replies:
    7
    Views:
    776
    Lars Uffmann
    Feb 21, 2008
  4. David Holroyd
    Replies:
    3
    Views:
    512
    David Holroyd
    May 25, 2005
  5. Randy General
    Replies:
    3
    Views:
    152
    Randy General
    Jul 8, 2009
Loading...

Share This Page