UDP thoroughput



Hello!

Sorry if it's a FAQ, but nevertheless:

Let's say I have a server that waits for UDP datagrams, and client that
sends 700 1000-byte datagrams as fast as it can over loop-back
interface. Upon receiving a datagram, server increments and prints a
counter. On average, only 75 datagrams arrive. If I add a timeout to
client, all 700 arrive. net.core.rmem_max = 8388608
Linux 2.6.13 i686
Is it expected behaviour? Is there anything to do about it?
My test code is below.

Thank you for any opinion,
Dmitri
(gone to read Stevens)

server:

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
int sock, length, fromlen, n=0;
struct sockaddr_in server;
struct sockaddr_in from;
char buf[2048];

sock=socket(AF_INET, SOCK_DGRAM, 0);
length = sizeof(server);
bzero(&server,length);
server.sin_family=AF_INET;
server.sin_addr.s_addr=INADDR_ANY;
server.sin_port=htons(1234);
bind(sock,(struct sockaddr *)&server,length);
fromlen = sizeof(struct sockaddr_in);
while (1) {
recvfrom(sock,buf,2048,0,(struct sockaddr *)&from,&fromlen);
printf("%d\n", n++);
}
}

client:

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
int i, sock, length, n;
struct sockaddr_in server, from;
struct hostent *hp;
unsigned char buffer[1095];

sock= socket(AF_INET, SOCK_DGRAM, 0);

server.sin_family = AF_INET;
hp = gethostbyname("localhost");

bcopy((char *)hp->h_addr, (char *)&server.sin_addr, hp->h_length);
server.sin_port = htons(1234);
length=sizeof(struct sockaddr_in);
for (i=0; i<1095; i++) buffer[i]=255;
buffer[0]=17; buffer[1]=0;
for (i=0; i<700; i++) {
sendto(sock,buffer,1095,0,&server,length);
/*usleep(1);*/
}
}

.



Relevant Pages

  • Re: strange behavior when the client bind its UDP socket to a local address
    ... nc does not reject datagrams, the UDP layer does because there is no matching UDP socket. ... Here is what netstat prints when the nc client is invoked with the following command line: ... But there's more about the nc server. ... Now I send a datagram from the client nc, and see what has become of the nc server socket: ...
    (comp.os.linux.networking)
  • Re: Get rid of gethostbyname
    ... the function "gethostbyname" to set the server name which is always ... int main(int argc, char *argv) ... int sockfd, portno, n; ... struct sockaddr_in serv_addr; ...
    (comp.unix.programmer)
  • newbie : strange behaviour of server
    ... I ` m doing the first step in client server programming, ... char recvbuffer; ... struct sockaddr_in server; ...
    (comp.unix.programmer)
  • Help - trying to serialize a struct
    ... I'm trying to convert a struct to a buffer of bytes, ... I can convert the struct to a char* (string ... server and he must be able to deserialize the information. ...
    (comp.lang.c)
  • Help - trying to serialize a struct
    ... I'm trying to converting a struct to a buffer of bytes, ... I can convert the struct to a char* (string ... server and he must be able to deserialize the information. ...
    (comp.lang.c)