zoukankan      html  css  js  c++  java
  • VC:检查端口是否打开

    1、

    void MySocket::OnConnect(int nErrorCode)

    {

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

           if(nErrorCode!=0)                              //连接失败

                  AfxMessageBox("端口关闭");

           else

                  AfxMessageBox("端口打开");

           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);

    //创建套接字

           BOOL flag=m_socket.Create();

           if(!flag)

           {

                  AfxMessageBox("SOCKET ERROR");

                  return;

           }

           m_socket.Connect(m_ipstr,m_port);//同时调用新建的类中的函数检测端口

    }

  • 相关阅读:
    Redis使用详细教程
    Web API 强势入门指南
    log4net
    ASP.NET Web API——选择Web API还是WCF
    Hadoop RPC机制
    力扣算法:每日温度
    力扣算法:完全平方数
    力扣算法:岛屿数量
    面试总结二
    面试总结
  • 原文地址:https://www.cnblogs.com/shenchao/p/2941072.html
Copyright © 2011-2022 走看看