Home > other >  Udp send and receive data, on the right of the following is a send and receive, accept 0 XFF becomes
Udp send and receive data, on the right of the following is a send and receive, accept 0 XFF becomes

Time:09-30

The switch (m_Send)
{
In case the CONNECTION:
Senddata publishes the event [0]=8;//length
-- -Senddata publishes the event [1]=0 XFF;//- target
Senddata publishes the event [2]=PC_NUM;//source
-- -Senddata publishes the event [3]=CONNECTION;//- type code
Senddata publishes the event [4]=GetCheckSum (senddata publishes the event, 4);//- checksum
Err=sendto (
UDPSocket,
Reinterpret_cast & lt; Char * & gt; (senddata publishes the event),
10,
0,
(const sockaddr *) & amp; S_RemoteAddr,
Sizeof (s_RemoteAddr)
);
//err=WSAGetLastError ();
//err=send (UDPSocket, reinterpret_cast & lt; Char * & gt; (senddata publishes the event), 10, 0);
If (err==SOCKET_ERROR)
{
MessageBox (_T (" failure "));
return FALSE;
}

//udp1DataReceived ();
break;//- send






Err=recvfrom (
UDPSocket,/* receive UDP data */
Reinterpret_cast & lt; Char * & gt; (RecvBuf),
BufLen,
0,
(sockaddr *) & amp; S_RemoteAddr,
(int *) & amp; Sockaddrlen
);
If (err==SOCKET_ERROR)/* Is the receive data right */
{
MessageBox (_T (" the receive data is failure!" ));
The UpdateData (FALSE);
return 0;
}

break;
  • Related