Solvline PB2xxxUG User Manual
Page 99
![background image](/manuals/711383/99/background.png)
// Construction
public:
CSockExamDlg(CWnd* pParent = NULL);
// standard constructor
CAsyncSocket * p;
CString
m_ipaddr;
………..
//Add the Connect button event in the class Wizard, and code as follows.
void CSockExamDlg::OnbtnConnect()
{
CEdit *pEdt;
// Finds the IP address.
pEdt= (CEdit *)GetDlgItem(IDC_edtIPAddress);
pEdt->GetWindowText(m_ipaddr);
// Creates the socket.
p = new CAsyncSocket;
p->Create();
// Requests a connection by the socket number 4001.
if(p->Connect((LPCSTR)m_ipaddr, 4001) == 0) {
AfxMessageBox("Connection
fail");
return;
}
else AfxMessageBox("Connection success");
// Sets a timer for transmission.
SetTimer(1, 3000, NULL);
// Sets a timer for transmission.
SetTimer(2, 1, NULL);
}
// Adds a coding for transmitting and receiving data in the timer event routine.
void CSockExamDlg::OnTimer(UINT nIDEvent)
{
CEdit * pEdt = (CEdit *)GetDlgItem(IDC_edtWINDOW);
99