简体   繁体   English

如何在C ++中将UDP数据报从Windows PC发送到Raspberry Pi

[英]How to send UDP datagrams from Windows PC to Raspberry Pi in C++

I would like to send datagrams (text commands) via UDP from a Windows PC to Raspberry Pi. 我想通过UDP从Windows PC向Raspberry Pi发送数据报(文本命令)。 The Windows PC will act as the client (sending the command) whilst the Raspberry Pi will be the server (receiving commands). Windows PC将充当客户端(发送命令),而Raspberry Pi将充当服务器(接收命令)。 I only managed to do it in Linux (which I can't use for various reasons) and besides that I could only send and receive packets from the same (one) PC. 我只能在Linux(由于各种原因而不能使用)上做到这一点,而且我只能从同一台(一台)PC发送和接收数据包。 Is it possible to do such thing, or would their be a conflict between Windows and Raspbian? 有可能这样做,还是Windows和Raspbian之间发生冲突? Thanks in advance. 提前致谢。

The protocol is same, how it can be in conflict. 该协议是相同的,如何可能会发生冲突。 Practically, API is close to BSD \\ POSIX, you just need make sure to intialise WinSocks with special call and cleanup it at end 实际上,API接近BSD \\ POSIX,您只需要确保通过特殊调用初始化WinSocks并在最后清理它

WSADATA            wsaData;
if( WSAStartup(MAKEWORD(2,2), &wsaData) != 0)
{
    printf("Server: WSAStartup failed with error %ld\n", WSAGetLastError());
    return -1;
}
else
    printf("Server: The Winsock DLL status is %s.\n", wsaData.szSystemStatus);

Call WSACleanup(); 调用WSACleanup(); when app doesn't need sockets anymore (before exit?) There is more to Winsock's than that 当应用程序不再需要套接字(退出之前?)时,Winsock的功能就不止于此

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM