12 #include <sys/types.h> 17 #include <sys/socket.h> 18 #include <netinet/in.h> 19 #include <arpa/inet.h> 27 #pragma comment(lib,"Ws2_32.lib") 30 #define LOCAL_SERVER_PORT 1500 33 int main(
int argc,
char *argv[]) {
37 struct sockaddr_in cliAddr, servAddr;
41 WSADATA wsaData = {0};
44 iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
46 wprintf(
L"WSAStartup failed: %d\n", iResult);
50 sd=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
53 sd=socket(AF_INET, SOCK_DGRAM, 0);
56 printf(
"%s: cannot open socket \n",argv[0]);
61 servAddr.sin_family = AF_INET;
62 servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
64 rc = bind (sd, (
struct sockaddr *) &servAddr,
sizeof(servAddr));
82 cliLen =
sizeof(cliAddr);
83 n = recvfrom(sd, msg,
MAX_MSG, flags, (
struct sockaddr *) &cliAddr,
87 printf(
"%s: cannot receive data \n",argv[0]);
91 printf(
"%s: from %s:UDP%u : %s \n", argv[0],
92 inet_ntoa(cliAddr.sin_addr), ntohs(cliAddr.sin_port), msg);
101 sendto(sd, msg, n, flags, (
struct sockaddr *)&cliAddr, cliLen);
int main(int argc, char *argv[])
static constexpr double L
#define LOCAL_SERVER_PORT
R__EXTERN C unsigned int sleep(unsigned int seconds)