Thread: UDP server/client performance in C

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

    UDP server/client performance in C

    Hi,

    I want to test the performance of server/client arhitecture that I wrote but I have problems with non-blocking sockets. When I use fcntl I can not run client and server to work at the same time. While I run server client has already sent 5000 replies back although the server is not start to stream. How
    can I make difference on client when server isn't turned on and when packet is lost? In my code client
    behaves same.
    On the other side, when I don't use fcntl then If I client doesn't receive packet
    it blocks and wait on that packet, he even don't sent a reply back. I want that
    client send back reply and to continue to receiving packets.


    I dont want to use sleep because I need real time performance.

    I'm wondering how real application are working, what is trick to implement this?

    Thx


    server
    Code:
        fcntl(socket,F_SETFL,O_NONBLOCK);
    
        while(1){
    
            sendto clients
            pthread_create(reply_processing)
      
        }
    
        reply_processing(){
    
            recvfrom_clients
    
       }
    client

    Code:
        fcntl(sd,F_SETFL,O_NONBLOCK);
    
    
        while(1){
    
            bytes = recvfrom server, buf
    
            if(nbytes != -1){
    
                if(buf > = 512) write
                else EOF return 1;
        
    
    
            }else{
    
                lost++
                nack sent
    
    }
        }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Well that's how UDP is supposed to work.

    If you want guarantees, then you need a TCP connection.

    The best thing to do is to establish a TCP connection to establish connectivity, and provide a reliable means of communication between the client and server.
    In parallel to that, you use UDP to stream volumes of data with minimal overhead, and build in a bit of tolerance for missing, duplicate, out-of-order packets.
    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.

  3. #3
    Registered User
    Join Date
    Jul 2012
    Posts
    45
    Well the problem is that I can not use TCP at all because broadcastin via TCP is not possible and that is excatly what I need, I broadcast stream to clients. Is there any way to control UDP, just this thing how to detect server activity as I explanied above?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Unless each client sends a periodic UDP message "I'm alive" and you hope enough messages get to the server for it to continue sending updates to the client.
    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

Similar Threads

  1. client server
    By kapil1089thekin in forum C Programming
    Replies: 1
    Last Post: 01-18-2011, 02:43 PM
  2. Client/server problem; server either stops receiving data or client stops sending
    By robot-ic in forum Networking/Device Communication
    Replies: 10
    Last Post: 02-16-2009, 11:45 AM
  3. Client-server on a LAN
    By Niara in forum Networking/Device Communication
    Replies: 3
    Last Post: 02-15-2006, 05:44 AM
  4. Client/Server
    By zonf in forum Networking/Device Communication
    Replies: 13
    Last Post: 12-18-2005, 11:12 AM
  5. client - server
    By Micko in forum Networking/Device Communication
    Replies: 3
    Last Post: 07-12-2004, 02:49 AM