Advertisement
ithoran

Kao server

Dec 19th, 2016
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. void main(int argc, char* argv[])
  2. {
  3.     WSAData wsa;
  4.     WSAStartup(0x0202, &wsa);
  5.  
  6.     SOCKET sock;
  7.     int addr_len, bytes_read;
  8.     char recv_data[1024];
  9.     char send_data[1024];
  10.     sockaddr_in server_addr, client_addr;
  11.  
  12.     if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == SOCKET_ERROR)
  13.     {
  14.         return;
  15.     }
  16.     server_addr.sin_family = AF_INET;
  17.     server_addr.sin_port = htons(5000);
  18.     server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  19.     if (bind(sock, (sockaddr*)&server_addr, sizeof(sockaddr_in)) == SOCKET_ERROR)
  20.     {
  21.         return;
  22.     }
  23.  
  24.     addr_len = sizeof(sockaddr);
  25.  
  26.     while (true)
  27.     {
  28.         bytes_read = recvfrom(sock, recv_data, 1024, 0, (sockaddr*)&client_addr, &addr_len);
  29.        
  30.         //nesto
  31.  
  32.         sendto(sock, send_data, strlen(send_data), 0, (sockaddr*)&client_addr, sizeof(sockaddr));
  33.     }
  34.  
  35.     closesocket(sock);
  36.     WSACleanup();
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement