|
- //创建
- BOOL CUDPSendVer1Dlg::CreateUdpSocket()
- {
- //char* csipbuf = "192.168.1.217";
- if (m_udpSockfd != INVALID_SOCKET)
- return TRUE;
- m_udpSockfd = socket(AF_INET,SOCK_DGRAM,0);
- if (m_udpSockfd == INVALID_SOCKET)
- {
- WSACleanup();//清理库
- return FALSE;
- }
- //网络的ip设置。
- memset(&m_serverAddr, 0, sizeof(SOCKADDR_IN));
-
- //m_serverAddr.sin_addr.s_addr = inet_addr(buf);//ip
- m_serverAddr.sin_addr.s_addr = inet_addr(ipbuf2);//ip
- m_serverAddr.sin_family = AF_INET;
- m_serverAddr.sin_port = htons(7000);//默认端口是1688 ip是192.168.1.25
- //绑定本地网卡接收ACK
- SOCKADDR_IN localAddr;
- localAddr.sin_addr.S_un.S_addr = htonl(INADDR_ANY);
- localAddr.sin_family = AF_INET;
- localAddr.sin_port = htons(7000);
- if(bind(m_udpSockfd,(SOCKADDR*)&localAddr,sizeof(SOCKADDR))<0)
- return FALSE;
- int mode=1; // noblocking
- ioctlsocket(m_udpSockfd, FIONBIO, (ULONG*)&mode);//非阻塞
- return TRUE;
- }
复制代码 |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|