Try this simple server and see if it works for you:
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define BUFSZ 4096
#define PORTNUM 1099
char buffer[BUFSZ];
int main( int argc, char* argv[] )
{
int fd;
struct sockaddr_in servaddr, cliaddr;
socklen_t clilen = sizeof( cliaddr );
ssize_t nread;
if (( fd = socket( AF_INET, SOCK_DGRAM, 0 )) == -1 )
err( 1, "socket" );
bzero( &cliaddr, sizeof( cliaddr ));
bzero( &servaddr, sizeof( servaddr ));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl( INADDR_ANY );
servaddr.sin_port = htons( PORTNUM );
if ( bind( fd, ( struct sockaddr* )&servaddr, sizeof( servaddr )) == -1 )
err( 1, "bind" );
printf( "bound to %s:%d\n", inet_ntoa( servaddr.sin_addr ),
ntohs( servaddr.sin_port ));
while (( nread = recvfrom( fd, buffer, BUFSZ, 0,
( struct sockaddr* )&cliaddr, &clilen )) != -1 )
{
printf( "received %lu bytes from %s:%d\n", nread,
inet_ntoa( cliaddr.sin_addr ),
ntohs( cliaddr.sin_port ));
}
return 1;
}
See if all the required steps are there in your code.