Code :
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <malloc.h> #include <ctype.h> #include <winsock.h> static int sock = -1; void sendudptolocal(char *buf, int len) { struct sockaddr_in addr; if (sock < 0) sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) return; memset(&addr, 0, sizeof addr); addr.sin_family = AF_INET; addr.sin_port = htons(12345); addr.sin_addr.s_addr = inet_addr("127.0.0.1" ); sendto(sock, buf, len, 0, (struct sockaddr*)&addr, sizeof(addr)); } int main(void) { WSADATA wsaData; WSAStartup(MAKEWORD(1,1), &wsaData); sendudptolocal("HELLO ", 6); sendudptolocal("WORLD!", 6); closesocket(sock); return 0; }
|