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);//同时调用新建的类中的函数检测端口

    }

  • 相关阅读:
    Two Sum II
    Subarray Sum
    Intersection of Two Arrays
    Reorder List
    Convert Sorted List to Binary Search Tree
    Remove Duplicates from Sorted List II
    Partition List
    Linked List Cycle II
    Sort List
    struts2结果跳转和参数获取
  • 原文地址:https://www.cnblogs.com/shenchao/p/2941072.html
Copyright © 2011-2022 走看看