C udp application simulate packet loss

This is a discussion on C udp application simulate packet loss within the C Programming forums, part of the General Programming Boards category; have udp server-client application written in C. On the client side packet loss is detected using recvfrom function and sequence ...

  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
    252
    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
    2,421
    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.
    Code:
    namespace life
    {
        const bool change = true;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simulate Keypress
    By silentkarma in forum Windows Programming
    Replies: 4
    Last Post: 02-28-2008, 11:59 PM
  2. Simulate Start->Run->OK
    By caduardo21 in forum Windows Programming
    Replies: 2
    Last Post: 01-13-2006, 10: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, 07:27 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21