#include #include #include #include #include #include #include #define MAXBUF 256 int main() { int ssock; int clen; struct sockaddr_in client_addr, server_addr; char buf[MAXBUF]; /* ¼ÒÄÏÀ» »ý¼ºÇÑ´Ù */ if ((ssock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { perror("socket error : "); exit(1); } /* ¼ÒÄÏ¿¡ ¿¬°áÇϱâ À§ÇÑ ¼­¹ö ¿É¼Ç °áÁ¤ */ memset(&server_addr, 0, sizeof(server_addr)); server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = htonl(INADDR_ANY); server_addr.sin_port = htons(3317); /* ¼ÒÄÏ¿¡ IP ÁÖ¼ÒµîÀÇ ¼­¹ö ¿É¼Ç ¼³Á¤ */ if (bind(ssock, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) { perror("bind error : "); exit(1); } /* UDP µ¥ÀÌÅ͸¦ ¼ö½ÅÇÑ´Ù */ recvfrom(ssock, (void *)buf, MAXBUF, 0, (struct sockaddr*)&client_addr, &clen); strcpy(buf, "I miss you"); /* UDP µ¥ÀÌÅ͸¦ Àü¼ÛÇÑ´Ù */ sendto(ssock, (void*)buf, MAXBUF, 0, (struct sockaddr*)&client_addr, sizeof(client_addr)); close(ssock); return 0; }