问题
[SOCKET PROGRAMMING] [UDP SERVER]
I am trying to do Message encryption and decryption using UDP server. Code is here: https://www.geeksforgeeks.org/message-encryption-decryption-using-udp-server/ But I am getting the following error:
fatal error: netinet/in.h: No such file or directory
How to resolve this issue?
回答1:
For the socket stuff on Windows you need #include <winsock2.h>
and you will also need to link with -lws2_32
.
In the beginning of your program you will also need to initialize the library like this:
static WSADATA wsaData;
int wsaerr = WSAStartup(MAKEWORD(2, 0), &wsaData);
if (wsaerr)
exit(1);
and clean before exiting like this:
WSACleanup();
For the rest most basic networking functions are the same as on *nix platforms, except for close()
which doesn't work on sockets, so you will need to do closesocket()
instead.
来源:https://stackoverflow.com/questions/62170418/fatal-error-netinet-in-h-no-such-file-or-directory