Thread: C udp application simulate packet loss

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    45

    C udp application simulate packet loss

    have udp server-client application written in C. On the client side packet loss is detected using recvfrom function and sequence numbers of packets. How can I now simulate dropped packet's on the client side, for example if server is sending 1000 packet I want to drop 20% of them? I want to do this in the code, not for example using ip tables or WANEM or something like that. And one more thing, I have few clients and I want that they can dropped different packets, not the same one.

    Code:
    while(1){
    
        nbytes = recvfrom(socket, buffer, MAX_SIZE, 0, (struct sockaddr *) &srv_addr, &addrlen);
    
            if (nbytes != -1) {
    
        // packet is received
    
            }else{
    
        //packet is not received
    
            }
    
    }

  2. #2
    Registered User
    Join Date
    Mar 2012
    Location
    the c - side
    Posts
    373
    On receiving each datagram generate a random number and if the number is in the lower e.g. 80% range let it pass else dump it.

    Different clients should have different sets of passed and dumped datagrams using this method.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    expanding on what gemera said, you could write wrapper functions for sendto and recvfrom (enabled or disabled by a debugging macro, for example), that would behave like their wrapped counterparts, but would decide whether to drop or pass the packets.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simulate Keypress
    By silentkarma in forum Windows Programming
    Replies: 4
    Last Post: 02-29-2008, 12:59 AM
  2. Simulate Start->Run->OK
    By caduardo21 in forum Windows Programming
    Replies: 2
    Last Post: 01-13-2006, 11:48 PM
  3. Networking (queuing delay, avg packet loss)
    By spoon_ in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 09-05-2005, 11:23 AM
  4. function to simulate sleep
    By golsoje in forum C++ Programming
    Replies: 19
    Last Post: 03-16-2002, 08:27 PM

Tags for this Thread