All pastes #2076375 Raw Edit

c_udp

public c v1 · immutable
#2076375 ·published 2011-06-07 20:18 UTC
rendered paste body
/* *  Client udp program  */#include <stdio.h>#include <string.h>#include <unistd.h>#include <stdlib.h>#include <error.h>#include <errno.h>#include <netdb.h>#define CHECK(x) \	if ( (x) == -1 ) { \	fprintf(stderr, "Error (@ %d) : %s\n",__LINE__, strerror(errno)); \	exit(-1); \	} int main (){	int sock;	struct sockaddr_in server, client;	char buffer[20];	CHECK ( sock = socket(PF_INET, SOCK_DGRAM | SOCK_NONBLOCK, 0));		       		memset(&client, '\0', sizeof client);        client.sin_addr.s_addr = inet_addr("127.0.0.1");        client.sin_port        = htons(9091);        client.sin_family      = PF_INET;	bind(sock, (struct sockaddr *)&client, sizeof(client));	memset(&server, '\0', sizeof server);	server.sin_addr.s_addr = inet_addr("127.0.0.1");	server.sin_port        = htons(9090);	server.sin_family      = PF_INET;		strcpy(buffer,"Hello World!");	CHECK( sendto( sock, buffer, 20, 0, 		       (struct sockaddr *)&server, sizeof(server)) );	return 0;}