ostName; SOCKADDR_IN addrTo; HOSTENT *pHost; if(GetDlgItemText(IDC_EDIT_HOSTNAME, strHostName), strHostName =="") {((CIPAddressCtrl *)GetDlgItem(IDC_IPADDRESS1))->GetAddress(dwIP); addrTo.sin_addr.S_un.S_addr =htonl(dwIP); } else {pHost =gethostbyname(strHostName); addrTo.sin_addr.S_un.S_addr =*((DWORD *)pHost->h_addr_list[0]); }addrTo.sin_family =; addrTo.sin_port =htons(6000); GetDlgItemText(IDC_EDIT_SEND, strSend); len =strSend.GetLength(); wsabuf.buf =strSend.GetBuffer(len); wsabuf.len =len +1; SetDlgItemText(IDC_EDIT_SEND, ""); if(SOCKET_ERROR ==WSASendTo(m_socket, &wsabuf, 1,&dwSend, 0,(SOCKADDR *)&addrTo, sizeof(SOCKADDR), NULL, NULL)) {MessageBox(" 发送数据失败"); return; }} 4. 系统调试在本地编译-组建-运行后的结果,如图 4-1 所示: 图4-1 在远程一台客户端运行同样的程序,在两台客户端中填入对方的 IP地址,如图 4-2 所示: 图4-2 在编辑框中填写发送的文字信息,如图 4-3 所示: