jweinst1
4/7/2020 - 9:35 AM

Send a datagram to the UDP server

Send a datagram to the UDP server

char SendBuf[1024];
int BufLen = (int)(sizeof(SendBuf) - 1);
const char* toSend = "foobar";
strcpy(SendBuf, toSend);

struct sockaddr_in ClientAddr;
int clientAddrSize = (int)sizeof(ClientAddr);
short port = 27015;
const char* local_host = "127.0.0.1";
ClientAddr.sin_family = AF_INET;
ClientAddr.sin_port = htons(port);
ClientAddr.sin_addr.s_addr = inet_addr(local_host);
puts("Sending a datagram to the receiver...");
    
int clientResult = sendto(SendSocket,
                     SendBuf, BufLen, 0, (SOCKADDR *) & ClientAddr, clientAddrSize);