⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcp_clientdlg.cpp

📁 TCP客户端应用开发示例。 EVC 4.0 编译通过 ARMV4I 运行成功
💻 CPP
📖 第 1 页 / 共 2 页
字号:

  
    int            usTmplen = 0;                                        /*  The temp length parameter   */
    char           pcTmpip[16];                                         /*  Temp buffer of the IP       */
                                                                        /*  addressto convert           */

    unsigned long  ulTmplocalip  = 0;                                   /*  Temp parameter of the local */
                                                                        /*  IP address                  */

    unsigned long  ulTmpremoteip = 0;                                   /*  Temp parameter of the remote*/
                                                                        /*  IP address                  */

    bool           bTmpret = false;                                     /*  Temp value of the return    */
    


    usTmplen = this->m_localip.GetWindowText(pusTmpip, 16);             /*  Get text from window  of the*/  
                                                                        /*  local IP address            */ 

    WideCharToMultiByte(CP_ACP, 
                        0, 
                        pusTmpip, 
                        usTmplen, 
                        pcTmpip, 
                        usTmplen, 
                        NULL, 
                        NULL);                                          /*  Convert the wide-character  */
                                                                        /*  string to the character     */
                                                                        /*  string                      */

    pcTmpip[usTmplen] = 0;                   
    
    ulTmplocalip = inet_addr(pcTmpip);                                  /*  Convert the dotted IP       */
                                                                        /*  address to the unsigned long*/
   
    usTmplen = this->m_remoteip.GetWindowText(pusTmpip, 16);            /*  Get text from window  of the*/  
                                                                        /*  remote IP address           */ 

    WideCharToMultiByte(CP_ACP, 
                        0, 
                        pusTmpip, 
                        usTmplen, 
                        pcTmpip, 
                        usTmplen, 
                        NULL, 
                        NULL);                                          /*  Convert the wide-character  */
                                                                        /*  string to the character     */
                                                                        /*  string                      */


    pcTmpip[usTmplen] = 0;

    ulTmpremoteip = inet_addr(pcTmpip);                                 /*  Convert the dotted IP       */
                                                                        /*  address to the unsigned long*/
  
    UpdateData(true);
   
    bTmpret = ctcpipLocal->epcProtocolStartup(__PT_TCP,
                                              ulTmplocalip,
                                              (unsigned short)this->m_localport,
                                              ulTmpremoteip,    
                                              (unsigned short)this->m_remoteport,
                                              __MODE_CLIENT);           /*  Startup UDP client server by*/
                                                                        /*  method of the TCP/IP class  */
    
    
    /*
     *  If startup is success, disable the button to open.
     */
    if (bTmpret) {                                                       
        this->m_open.EnableWindow(false);    
        this->m_remoteip.EnableWindow(false);

        CEdit * ceditTmp = (CEdit *)GetDlgItem(IDC_EDIT_remoteport); 
        ceditTmp->EnableWindow(false);
        this->m_localip.EnableWindow(false);
        ceditTmp = (CEdit *)GetDlgItem(IDC_EDIT_localport); 
        ceditTmp->EnableWindow(false);
    } else {
        MessageBox(_T("连接远程主机失败!"),
                   _T("失败"),
                   MB_ICONERROR);
    }
}

void CTcp_clientDlg::OnBUTTONclose() 
{
	 unsigned short pusTmpip[16];                                       /*  Temp buffer of the IP       */
                                                                        /*  address from window         */

  
    int            usTmplen = 0;                                        /*  The temp length parameter   */
    char           pcTmpip[16];                                         /*  Temp buffer of the IP       */
                                                                        /*  addressto convert           */

    unsigned long  ulTmplocalip  = 0;                                   /*  Temp parameter of the local */
                                                                        /*  IP address                  */
   

    bool           bTmpret = false;                                     /*  Temp value of the return    */
    


    usTmplen = this->m_remoteip.GetWindowText(pusTmpip, 16);            /*  Get text from window  of the*/  
                                                                        /*  local IP address            */ 

    WideCharToMultiByte(CP_ACP, 
                        0, 
                        pusTmpip, 
                        usTmplen, 
                        pcTmpip, 
                        usTmplen, 
                        NULL, 
                        NULL);                                          /*  Convert the wide-character  */
                                                                        /*  string to the character     */
                                                                        /*  string                      */
	ulTmplocalip = inet_addr(pcTmpip);  

	UpdateData(true);

    bTmpret = ctcpipLocal->epcProtocolClose(ulTmplocalip, (unsigned short)this->m_remoteport);
    this->m_open.EnableWindow(true);	                                /*  Enable the button to open   */
    this->m_remoteip.EnableWindow(true);

    CEdit * ceditTmp = (CEdit *)GetDlgItem(IDC_EDIT_remoteport); 
    ceditTmp->EnableWindow(true);
    this->m_localip.EnableWindow(true);
    ceditTmp = (CEdit *)GetDlgItem(IDC_EDIT_localport); 
    ceditTmp->EnableWindow(true);	
    this->EndDialog(0);
}

void CTcp_clientDlg::OnBUTTONrxclr() 
{
    /*
     *  Clear buffer and index of the received buffer
     */
    this->usIndex = 0;                                  
    this->m_rx.SetWindowText(_T(""));	
}

void CTcp_clientDlg::OnBUTTONtxclr() 
{
    this->m_tx.SetWindowText(_T(""));	                                /*  Clear buffer of the window  */
                                                                        /*  to send                     */	
}

void CTcp_clientDlg::OnBUTTONsend() 
{
    unsigned short pusTmpip[16];
    int            usTmplen = 0;
    char           pcTmpip[16];
    unsigned long  ulTmpRemoteip;
    
    /*
     *  Get the remote IP address and the remote IP port
     *  from the window, and convert to the specify style.
     */
    usTmplen = this->m_remoteip.GetWindowText(pusTmpip, 16);
    WideCharToMultiByte(CP_ACP, 
                        0, 
                        pusTmpip, 
                        usTmplen, 
                        pcTmpip, 
                        usTmplen, 
                        NULL, 
                        NULL);
    pcTmpip[usTmplen] = 0;
    ulTmpRemoteip = inet_addr(pcTmpip);

    char           pcTmpsendbuf[RX_BUF_SIZE];                           /*  Temp buffer of the send data*/
                                                                        /*  to send                     */

    unsigned short pusTmpsendbuf[RX_BUF_SIZE];                          /*  Temp buffer of the send data*/
                                                                        /*  to convert                  */                    
   
    usTmplen = this->m_tx.GetWindowText(pusTmpsendbuf, RX_BUF_SIZE);    /* Get the send data from the   */
                                                                        /*  window                      */

    WideCharToMultiByte(CP_ACP, 
                        0, 
                        pusTmpsendbuf, 
                        usTmplen, 
                        pcTmpsendbuf, 
                        usTmplen, 
                        NULL, 
                        NULL);                                          /*  Convert the wide-character  */
                                                                        /*  string to the character     */
                                                                        /*  string                      */

	this->ctcpipLocal->epcProtocolSenddata(ulTmpRemoteip,
                                           (unsigned short)this->m_remoteport,
                                           pcTmpsendbuf,
                                           (unsigned short)usTmplen);	/*  Send data by method of the */
                                                                        /*  TCP/IP class               */	
}

void CTcp_clientDlg::OnClose() 
{
	delete ctcpipLocal;
	
	CDialog::OnClose();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -