MFC UDP

#include <afxsock.h>		// MFC socket extensions

BOOL ...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 here
	
	m_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);  
} 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值