Thread: C sendto works sometimes…just stops after some time… NO ERRORS

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    1

    C sendto works sometimes…just stops after some time… NO ERRORS

    Hey,

    Ive been getting strange results with the sendto function in C.(LINUX) What I am trying to do is to implement a reliable UDP kind of scheme.

    The snippet of code provided below is a part of the timer that expires when a packet is dropped and sends a message to a process to retransmit that packet.

    The weird problem which I am having is that when transferring a large file say... >300KB The code given below works perfectly (i.e. THE ELSE PART IS EXECUTED) But after a certain number of packets are sent...it executes the then part.!!!

    THIS IS STRANGE BECAUSE THE CODE WORKED FINE FOR ABOUT 250 PACKETS BUT WITH THE 251 PACKET kabooom!!!

    n = sendto(sockfd, &(forwardPeer->id), sizeof(forwardPeer->id), 0, (struct sockaddr*)&tcpd_addr, sizeof(tcpd_addr));
    if(n<0)
    printf("\n error sending to tcpdc");
    else
    printf("\n message sent to tcpdc");

    I tried with strerror and got an error number of 134514723
    Perror gives Unknown File descriptor

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Print the value stored in sockfd (that is, print it in the error message)
    Is it a garbage value, or good?

    Check elsewhere to see if the socket has been closed.

    Have you tried running the code in the debugger (gdb)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Tags for this Thread