본문 바로가기

Windows Programming/Windows Socket

(4)
C언어 Echo Client (1:1통신) #include #include #include #include #pragma comment(lib, "ws2_32")#define PORT 7777#define SERVER_IP "127.0.0.1"int main(void){ WSADATA wsaData = { 0, }; SOCKADDR_IN Addr = { 0, }; char strInput[MAX_PATH] = { 0, }, cRecvBuf[MAX_PATH] = { 0, }; SOCKET hSocket = NULL; int nErrorCode = 0; WSAStartup(MAKEWORD(2, 2), &wsaData); hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (hSocket..
C언어 Echo Server (1:1 통신) #define _CRT_SECURE_NO_WARNINGS#include #include #include #include #pragma comment(lib, "ws2_32")#define PORT 7777int main(void) { printf("Sever Working...\n\n"); WSADATA wsaData = { 0, }; SOCKADDR_IN listnAddr = { 0, }; SOCKADDR_IN ClntAddr = { 0, }; char buf[MAX_PATH] = { 0, }; SOCKET hListen = NULL; int iClntSize = 0, nErrorCode = 0; WSAStartup(MAKEWORD(2, 2), &wsaData); hListen = soc..
Windows Socket (Server) 윈도우 기반 서버 소켓 기본 코드 입니다. #include #include #include #include #pragma comment(lib, "ws2_32") #define PORT 8088 #define MAXSIZE 256 #define PACKET_SIZE 1024 int main(int argc, char *argv[]) { WSADATA wsaData; SOCKET hListen; int nRecv = 0; char buf[MAXSIZE] = { 0, }; WSAStartup(MAKEWORD(2, 2), &wsaData); hListen = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (hListen == -1) ErrorMsg("Socket Error!..
Windows Socket (Client) 윈도우 기반 클라이언트 소켓 기본 코드입니다. #include #include #include #include // #pragma comment(lib, "ws2_32") // #define PORT 5000 #define MAXSIZE 256 #define PACKET_SIZE 1024 #define SERVER_IP "127.0.0.1" // int main(void) { WSADATA wsaData; SOCKET hSocket; WSAStartup(MAKEWORD(2, 2), &wsaData); hSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (hSocket == -1) ErrorMsg("Socket() Error!"); SOCKADDR_IN Ad..