Async Client Code Flashcards
Includes?
include <winsock2.h></winsock2.h>
Globals
CSOCKET ClientSocket;
Inside WinProc
WORD WSAEvent, WSAErr;
//after switch
return(DefWindowProc(hWnd, iMsg, wParam, lParam));
inside WinProc()
inside
switch (iMsg)
case ASYNC_MSG:
{
WSAEvent = WSAGETSELECTEVENT(lParam);
WSAErr = WSAGETSELECTERROR(lParam);
switch (WSAEvent)
{
case FD_READ:
case FD_CONNECT:
case FD_WRITE:
case FD_CLOSE:
default:break;
};
}break;
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case ID_FILE_CONNECT:
case ID_FILE_DISCONNECT:
default: break;
break;
}break;
case WM_DESTROY:
default:break;
};
inside
case ASYNC_MSG:
switch (WSAEvent)
case FD_READ:
case FD_READ:
{
MessageBox(hWnd, “Read Recieved”,
“Message Inbox”, MB_OK);
Rec = ClientSocket.Recv(ClientSocket.RecvData, 80);
ShowMe(HLB_Output, ClientSocket.RecvData);
break;
}
inside
case ASYNC_MSG:
switch (WSAEvent)
case FD_CONNECT:
case FD_CONNECT:
{
MessageBox(hWnd, “Connect Recieved”,
“Message Inbox”, MB_OK);
}break;
inside
case ASYNC_MSG:
switch (WSAEvent)
case FD_WRITE:
case FD_WRITE:
{
MessageBox(hWnd, “Write Recieved”,
“Message Inbox”, MB_OK);
ShowMe(HLB_Output, “Successfully connected to server”);
ClientSocket.Send(“Susie Watkins”, 15);
}break;
inside
case ASYNC_MSG
switch (WSAEvent)
case FD_CLOSE:
case FD_CLOSE:
{
MessageBox(hWnd, “Close Recieved”,
“Message Inbox”, MB_OK);
}break;
inside
case WM_COMMAND:
switch (LOWORD(wParam))
case ID_FILE_CONNECT:
case ID_FILE_CONNECT:
{
char ServerIP[20];
char szPort[5];
GetWindowText(HEB_IP, ServerIP, 20);
GetWindowText(HEB_PORT, szPort, 5);
ClientSocket.iPort = atoi(szPort);
int iRet = ClientSocket.Connect(hWnd, TCP,
ServerIP);
}break;
inside
case WM_COMMAND:
switch (LOWORD(wParam))
case ID_FILE_DISCONNECT:
case ID_FILE_DISCONNECT:
{
ClientSocket.Disconnect();
ShowMe(HLB_Output, “Disconnected”);
}break;
inside
case WM_DESTROY:
case WM_DESTROY:
// Cleanup System
// Exit out of Windows
ClientSocket.Disconnect();
PostQuitMessage(0);
break;