All pastes #197072 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-10-11 02:08 UTC
rendered paste body
#include <stdio.h>
#include <winsock.h>
int main()
{
	 struct sockaddr_in ServerAddress; 
     int socket_GLOBAL; 
	 struct sockaddr_in ClientAddress; 
	 char receivedpacket[2000];
	 char Response = "This is a packet";
	 int sizeofClientAddress = sizeof(ClientAddress);
     WSADATA wsa; 
 
     WSAStartup(MAKEWORD(1, 1), &wsa); 
 
     socket_GLOBAL = socket(AF_INET,SOCK_DGRAM, IPPROTO_UDP); 
	 memset(&ServerAddress, 0, sizeof(ServerAddress)); 
     ServerAddress.sin_family = AF_INET; 
     ServerAddress.sin_port = htons(4447); //port=whatever nmasterneeds to be on 
     ServerAddress.sin_addr.s_addr=INADDR_ANY; //I hope this doesn't cause problems 

 	 bind(socket_GLOBAL, (struct sockaddr *)&ServerAddress, sizeof(ServerAddress));

	 recvfrom(socket_GLOBAL, (char *)receivedpacket, 1999, 0, (struct sockaddr *)&ClientAddress, &sizeofClientAddress);	 
	 
	 sendto(socket_GLOBAL, (char *)Response, (char *)strlen(Response), 0, (struct sockaddr *)&ClientAddress, &sizeof(ClientAddress));
   
    }