Liea
'③ 공부/TCP, IP Socket Programming' 카테고리의 글 목록

③ 공부/TCP, IP Socket Programming

③ 공부/TCP, IP Socket Programming

main_에코서버(이벤트)

#include "MySocketError.h" #include "MySystemError.h" #define MAXCLIENT 100 //현재 접속한 클라이언트의 소켓 정보 SOCKET clientSockets[MAXCLIENT]; int clientCount; //클라이언트들이 접속하면 하나씩 쓰레드가 만들어진다. unsigned int _stdcall ThreadFunc(void* lpParameter); //q만을 감시해서 모든 클라이언트 접속을 끊어버리겠다. unsigned int _stdcall ThreadFuncExit(void* lpParameter); //CRITICAL_SECTION cs; //HANDLE hMutex; //HANDLE hSemaphore; HANDLE hEvent; v..

③ 공부/TCP, IP Socket Programming

main_에코서버(세마포어)

#include "MySocketError.h" #include "MySystemError.h" #define MAXCLIENT 100 //현재 접속한 클라이언트의 소켓 정보 SOCKET clientSockets[MAXCLIENT]; int clientCount; //클라이언트들이 접속하면 하나씩 쓰레드가 만들어진다. unsigned int _stdcall ThreadFunc(void* lpParameter); //q만을 감시해서 모든 클라이언트 접속을 끊어버리겠다. unsigned int _stdcall ThreadFuncExit(void* lpParameter); //CRITICAL_SECTION cs; //HANDLE hMutex; HANDLE hSemaphore; void TotalClients(..

③ 공부/TCP, IP Socket Programming

main_에코서버(뮤텍스)

#include "MySocketError.h" #include "MySystemError.h" #define MAXCLIENT 100 //현재 접속한 클라이언트의 소켓 정보 SOCKET clientSockets[MAXCLIENT]; int clientCount; //클라이언트들이 접속하면 하나씩 쓰레드가 만들어진다. unsigned int _stdcall ThreadFunc(void* lpParameter); //q만을 감시해서 모든 클라이언트 접속을 끊어버리겠다. unsigned int _stdcall ThreadFuncExit(void* lpParameter); //CRITICAL_SECTION cs; HANDLE hMutex; void TotalClients(void); int _tmain(voi..

③ 공부/TCP, IP Socket Programming

main_에코서버(크리티컬섹션으로)

#include "MySocketError.h" #include "MySystemError.h" #define MAXCLIENT 100 //현재 접속한 클라이언트의 소켓 정보 SOCKET clientSockets[MAXCLIENT]; int clientCount; //클라이언트들이 접속하면 하나씩 쓰레드가 만들어진다. unsigned int _stdcall ThreadFunc(void* lpParameter); //q만을 감시해서 모든 클라이언트 접속을 끊어버리겠다. unsigned int _stdcall ThreadFuncExit(void* lpParameter); CRITICAL_SECTION cs; void TotalClients(void); int _tmain(void) { _tsetlocale(..

③ 공부/TCP, IP Socket Programming

시스템 프로그래밍 : 파일 그리고 쓰레드를 제어하는 동기화모듈들(뮤텍스 세마포어 이벤트 크리티컬섹션)

2._tmain_STDIO의 파일함수로 파일을 카피하자(TCHAR).cpp #include "MySystemError.h" #define MAXSTRING 100 enum{READ,WRITE }; //#define READ 0 #define WRITE 1 int _tmain(void) { _tsetlocale(LC_ALL, _T("korean")); //1.copy할 파일의 이름을 저장한다. TCHAR filename[2][MAXSTRING] = { 0 }; if (!SelectOpenFile(filename[READ])) return -1; if (!SelectSaveFile(filename[WRITE])) return -1; for (int i = 0; i < 2; i++) _tprintf(_T("[..

③ 공부/TCP, IP Socket Programming

시스템 프로그래밍 : 쓰레드를 제대로 써보자

main_다수의 쓰레드를 만들어보자(안정화된 함수를 사용하기도 하고).cpp #include "MySystemError.h" #define MAX 100000 #define MAXTHREAD 100 int total = 0;//전역변수 DWORD WINAPI ThreadFunc(LPVOID IpParameter); HANDLE hMutex; int _tmain(void) { hMutex = CreateMutex(NULL, FALSE, NULL); if (!hMutex) SystemErrorMsg(_T("CreateMutex")); else SystemOKMsg(_T("CreateMutex")); BOOL result = FALSE; _tsetlocale(LC_ALL, _T("korean")); HANDL..

③ 공부/TCP, IP Socket Programming

시스템 프로그래밍 : 독립적인 존재 쓰레드

SystemError.h #pragma once #include//OS windows, window(s) #include #include #include #ifdef UNICODE #define SystemErrorExit SystemErrorExitW #define SystemErrorMsg SystemErrorMsgW #define SystemOKMsg SystemOKMsgW #else #define SystemErrorExit SystemErrorExitA #define SystemErrorMsg SystemErrorMsgA #define SystemOKMsg SystemOKMsgA #endif //System error void SystemErrorExitA(const char* str); //p..

③ 공부/TCP, IP Socket Programming

시스템 프로그래밍 : 문자셋(char wchar_t TCHAR 아스키코드 유니코드 템플릿 캐릭터)

SocketError.h #pragma once #include //WSAAddressToString,WSAStringToAddress #include //inet_pton,inet_ntop,InetPton,InetNtop #include #include #include #define SERVER_IPPORT L"127.0.0.0:60000" /*#ifdef UNICODE #define ErrorExit wErrorExit #define ErrorMsg wErrorMsg #define OKMsg wOKMsg #else #define ErrorExit _ErrorExit #define ErrorMsg _ErrorMsg #define OKMsg _OKMsg #endif*/ void ErrorExit(cons..