*Client
Connect시 Thread 실행됨.
//스레드
UINT ThreadIOEvent(LPVOID pParam){
CString tmp = _T("");
char szBuffer[U_BUFSIZE];
//create event
WSAEVENT hEvent = ::WSACreateEvent();
//registry event
if(::WSAEventSelect(g_hSocket,hEvent,FD_READ|FD_CLOSE) == SOCK_ERROR){
tmp.Format(_T("WSAEventSelect Error. [Error Code:%d]"),::WSAGetLastError());
AfxMessageBox(tmp);
::WSACloseEvent(hEvent);
return 0;
}
//wait for asynchronous events
WSANETWORKEVENTS WsaNetEvent;
while(::WSAWaitForMultipleEvents(1,&hEvent,TRUE,WSA_INFINITE,TRUE){
::WSAEnumNetworkEvents(g_hSocket,hEvent,&WsaNetEvent);
switch(WsaNetEvent.lNetworkEvents){
case FD_CLOSE: //connection close
AfxMessageBox(_T("Connection Close"));
::shutdown(g_hSocket,FD_BOTH); //빈칸
ExitProcess(0);
break;
case FD_READ: //read event //빈칸
break;
}
}
::WSACloseEvent(hEvent);
return 0;
}
-빈칸은 소스보고 채우자. 프리렉가면 나온다.
Programming/Tips(C++,C#)
02/02 - Async version
반응형
댓글