Advertisement
ithoran

WAT IS GOIN ON

Dec 12th, 2016
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. // MrezeEE.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <winsock.h>
  8. #pragma comment(lib, "wsock32.lib")
  9.  
  10. void main(int argc, char* argv[])
  11. {
  12.     WSAData wsa;
  13.     WSAStartup(0x0202, &wsa);
  14.  
  15.     SOCKET sock;
  16.     int addr_len, bytes_read;
  17.     char recv_data[1024];
  18.     char send_data[1024];
  19.     sockaddr_in server_addr, client_addr;
  20.     char* m_sServerIP = "10.10.77.215";
  21.  
  22.     if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == SOCKET_ERROR)
  23.     {
  24.         return;
  25.     }
  26.     server_addr.sin_family = AF_INET;
  27.     server_addr.sin_port = htons(5000);
  28.     server_addr.sin_addr.s_addr = inet_addr(m_sServerIP);
  29.  
  30.     addr_len = sizeof(sockaddr);
  31.  
  32.     while (true)
  33.     {
  34.         printf("ja: ");    
  35.         gets(send_data);
  36.  
  37.         sendto(sock, send_data, strlen(send_data)+1, 0, (sockaddr*)&server_addr, addr_len);
  38.        
  39.         bytes_read = recvfrom(sock, recv_data, 1024, 0, (sockaddr*)&client_addr, &addr_len);
  40.  
  41.         printf("server: %s\n", recv_data);
  42.     }
  43.  
  44.     closesocket(sock);
  45.     WSACleanup();
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement