Udp

//server

CSocket t;

       t.Create(2000,SOCK_DGRAM,"127.0.0.1");

       t.Bind(2000,"127.0.0.1");

       char buf[1024]="hi1";

    t.SendTo(buf,strlen(buf),2000,"127.0.0.1",0);

//client

       CString add="127.0.0.1";

       UINT port=2000;

       ::AfxMessageBox(buf);

       int len=t.ReceiveFrom(buf,1023,add,port,0);

       buf[len+1]='\0';

       ::AfxMessageBox(buf);

Tcp

BOOL CNetDlg::OnInitDialog()

{

……………..

cs.Create(2222);

       cs.Listen(5);

cs.m_dlg=this;

}

void CNetDlg::accept()

{

     ccs t;

     if(!cs.Accept(t))

        return;

 

        char buf[1024];

     int len=t.Receive(buf,1024,0);

        

        buf[len+1]='\0';

        m_l.AddString(buf);

        t.Close();

}

Csocket继承类

void ccs::OnAccept(int nErrorCode) //消息

{

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

      

       m_dlg->accept();

       CSocket::OnAccept(nErrorCode);

}

相关文章:

  • 2022-02-17
  • 2022-12-23
  • 2021-10-26
  • 2021-06-14
  • 2022-01-24
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-09
  • 2022-12-23
  • 2022-01-21
  • 2022-12-23
  • 2022-01-12
  • 2021-11-28
相关资源
相似解决方案