-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDemoSocket.cpp
More file actions
55 lines (48 loc) · 904 Bytes
/
DemoSocket.cpp
File metadata and controls
55 lines (48 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// mySocket.cpp : ʵÏÖÎļþ
//
#include "stdafx.h"
#include "DemoSocket.h"
#include "UIDemoDlg.h"
// mySocket
CDemoSocket::CDemoSocket()
: m_pWnd(NULL)
{
}
CDemoSocket::~CDemoSocket()
{
if(m_hSocket !=INVALID_SOCKET)
{
Close();
}
}
void CDemoSocket::SetParent(CDialog *pWnd)
{
m_pWnd = pWnd;
}
void CDemoSocket::OnReceive(int nErrorCode)
{
ASSERT(m_pWnd);
m_pWnd->SendMessage(WM_SOCKET_RECEIVE);
CAsyncSocket::OnReceive(nErrorCode);
}
void CDemoSocket::OnClose(int nErrorCode)
{
ASSERT(m_pWnd);
m_pWnd->SendMessage(WM_SOCKET_CLOSE);
CAsyncSocket::OnClose(nErrorCode);
}
void CDemoSocket::OnConnect(int nErrorCode)
{
if (!nErrorCode)
{
ASSERT(m_pWnd);
m_pWnd->SendMessage(WM_SOCKET_CONNECT);
CAsyncSocket::OnClose(nErrorCode);
}
else
{
/* CString str;
str.Format(_T("连接错误,错误码:%d"),nErrorCode);
AfxMessageBox(str);*/
}
}