#include <stdio.h> #include <winsock2.h> #define PORT_NUM 3800 #define MAXLEN 1024 int main(int argc, char **argv) { SOCKET sockfd; WSADATA wsaData; struct sockaddr_in addr; char buf[MAXLEN]; char rbuf[MAXLEN]; if(argc !=2) { printf("Usage : %s [ip address]\n", argv[0]); return 1; } if(WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR) { return 1; } if((sockfd = socket(AF_INET,SOCK_STREAM, 0)) == INVALID_SOCKET) { return 1; } memset((void *)&addr, 0x00, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr(argv[1]); addr.sin_port = htons(PORT_NUM); if(connect(sockfd, (struct sockaddr *)&addr, sizeof(addr)) == SOCKET_ERROR) { return 1; } while(1) { printf("> "); fgets(buf, MAXLEN-1, stdin); if(strncmp(buf, "quit\n",5) == 0) { break; } send(sockfd, (void *)buf, strlen(buf), 0); memset(rbuf, 0x00, MAXLEN); recv(sockfd, (void *)buf, MAXLEN, 0); printf("s -> %s\n", buf); } closesocket(sockfd); WSACleanup(); return 0; }
Copyrights © - Joinc, All Rights Reserved. Inherited From - Yundream Rebranded By - Joonphil
echo 클라이언트 프로그램
관련 글
Recent Posts
Archive Posts
Tags