VC: Check whether the port is enabled

Source: Internet
Author: User
Tags socket error

1,

Void MySocket: OnConnect (int nErrorCode)

{

// TODO: Add your specialized code here and/or call the base class

If (nErrorCode! = 0) // connection failed

AfxMessageBox ("port closed ");

Else

AfxMessageBox ("Open Port ");

 

CAsyncSocket: OnConnect (nErrorCode );

}

2,

CString m_ipstr;

MySocket m_socket;

 

Void CTestDlg: OnConnect ()

{

// TODO: Add your control notification handler code here

If (! AfxSocketInit ())

{

AfxMessageBox ("IDP_SOCKETS_INIT_FAILED ");

Return;

}

GetDlgItemText (IDC_IPADDRESS1, m_ipstr );

M_socket.m_hSocket = INVALID_SOCKET;

UpdateData (true );

// Create a socket

BOOL flag = m_socket.Create ();

If (! Flag)

{

AfxMessageBox ("socket error ");

Return;

}

M_socket.Connect (m_ipstr, m_port); // call the function detection port in the new class at the same time.

 

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.