Advertisement
Zgragselus

Simple connection to RTL1090

Oct 20th, 2020
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. WSADATA wsa;
  2. if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
  3. {
  4.     std::cout << "ERROR: WSAStartup failed" << std::endl;
  5.     std::cin.get();
  6. }
  7.  
  8. SOCKET s;
  9. if ((s = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
  10. {
  11.     std::cout << "ERROR: Can't create socket - " << WSAGetLastError() << std::endl;
  12.     std::cin.get();
  13. }
  14.  
  15. struct sockaddr_in server;
  16. server.sin_family = AF_INET;
  17. server.sin_addr.s_addr = inet_addr("127.0.0.1");
  18. server.sin_port = htons(31001);
  19.  
  20. if (connect(s, (struct sockaddr*)&server, sizeof(server)) < 0)
  21. {
  22.     std::cout << "ERROR: Can't connect to server" << std::endl;
  23.     std::cin.get();
  24. }
  25.  
  26. std::cout << "INFO: Connected to server" << std::endl;
  27. std::cin.get();
  28.  
  29. // Now we can send/receive data
  30.  
  31. closesocket(s);
  32. WSACleanup();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement