如果可以的话我把代码发来看能否帮助调试以下void CP2PDlg::OnButtonSendMessage() 
{//发送消息
// TODO: Add your control notification handler code here
    UpdateData(true);
if(!m_message.IsEmpty())
{
CSocket msocket;
int i=atoi(m_port);
msocket.Create(5000);
//以数据报形式发送消息
/* //将IPAddressCtrl中的IP地址获得并转换成CString型*/
DWORD dwIP;
unsigned char *pIP;
CString strIP;
m_ipctrl.GetAddress(dwIP);
pIP = (unsigned char*)&dwIP;
strIP.Format("%u.%u.%u.%u",*(pIP+3), *(pIP+2), *(pIP+1), *pIP);
int length=m_message.GetLength();
int j=msocket.SendTo(m_message,length,i,strIP,0);

CString jinfo;
jinfo.Format("%d",j);//-1
AfxMessageBox(jinfo);
//获得焦点发送信息,端口号为5000
CString info;
info.Format("本机-->%s:%s",strIP,m_message);
m_history.AddString(info);
UpdateData(false);
}else
{
AfxMessageBox("不能发送空消息!");
}
}UINT MyThreadProc( LPVOID lparam)
{//接受消息功能
CString sockadd;
CSocket sock;
int nRet=0;
sock.Create(5000);
//接受信息
CP2PDlg *dlg=(CP2PDlg*) AfxGetApp()->GetMainWnd();
while(1)
{
nRet=sock.Receive(tchar_message,100);
//接受消息
if(nRet!=SOCKET_ERROR)
{
AfxBeginThread(MyThreadProc,0,THREAD_PRIORITY_NORMAL,
                  0,CREATE_SUSPENDED);
strmessinfo.Format("-->本机:%100s",tchar_message);
dlg->m_history.AddString(strmessinfo);
dlg->UpdateData(false);
}else 
{
dlg->m_history.AddString("socket error");
}
AfxEndThread(0);
return 0;
}
}