#include"winsock2.h"
voidmain(){
WSADATAwsaData;
SOCKETSendSocket;
sockaddr_inRecvAddr;
intPort=27015;
charSendBuf[1024];
intBufLen=1024;
//---------------------------------------------
//InitializeWinsock
WSAStartup(MAKEWORD(2,2),&wsaData);
//---------------------------------------------
//Createasocketforsendingdata
SendSocket=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
//---------------------------------------------
//SetuptheRecvAddrstructurewiththeIPaddressof
//thereceiver(inthisexamplecase"123.456.789.1")
//andthespecifiedportnumber.
RecvAddr.sin_family=AF_INET;
RecvAddr.sin_port=htons(Port);
RecvAddr.sin_addr.s_addr=inet_addr("123.456.789.1");
//---------------------------------------------
//Sendadatagramtothereceiver
printf("Sendingadatagramtothereceiver...\n");
sendto(SendSocket,
SendBuf,
BufLen,
0,
(SOCKADDR*)&RecvAddr,
sizeof(RecvAddr));
//---------------------------------------------
//Whentheapplicationisfinishedsending,closethesocket.
printf("Finishedsending.Closingsocket.\n");
closesocket(SendSocket);
//---------------------------------------------
//Cleanupandquit.
printf("Exiting.\n");
WSACleanup();
return;
}