MFC UDP

来源:互联网 发布:虹港数据 idc机房 编辑:程序博客网 时间:2024/06/04 11:32
#include <afxsock.h>// MFC socket extensionsBOOL ...App::InitInstance(){if (!AfxSocketInit()){AfxMessageBox(IDP_SOCKETS_INIT_FAILED);return FALSE;}//////////////////////////////////////////////////////////////////////class CDSocket : public CSocket  void CFasonDlg::OnSend()   {      // TODO: Add your control notification handler code here      UpdateData(TRUE);      CString m_Getstring;            this->m_Cob.GetLBText(m_Cob.GetCurSel(),m_Getstring);      if(m_Getstring==_T("Red"))      yuan1.color=1;      if(m_Getstring==_T("Green"))          yuan1.color=2;      if(m_Getstring==_T("Blue"))          yuan1.color=3;            yuan1.x=m_x;      yuan1.y=m_y;      yuan1.r=m_r;        p=&yuan1;        CDSocket m_hSocket;      m_hSocket.Create(2330,SOCK_DGRAM);      m_hSocket.SendTo( p,sizeof(yuan1),3550,"127.0.0.1");        m_x=0;      m_y=0;      m_r=0;      m_hSocket.Close();      UpdateData(FALSE);  }  //////////////////////////////////////////////////////////////////////  class CDASocket : public CAsyncSocket  CJieshouDoc::CJieshouDoc(){// TODO: add one-time construction code herem_hSocket=new CDASocket(this);m_hSocket->Create(3550,SOCK_DGRAM);}  void CDASocket::OnReceive(int nErrorCode)   {      // TODO: Add your specialized code here and/or call the base      char buff[256];      int ret=0;      ret=Receive(buff,256);      if(ret==ERROR)      {          TRACE("ERROR!");      }      else           m_pDoc->Presscessding(buff);      class CAsyncSocket::OnReceive(nErrorCode);  }