Advertisement
informaticage

winsock

Oct 14th, 2014
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <windows.h>
  2. #include <winsock2.h>
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <cstdlib>
  6.  
  7. #pragma comment(lib, "Ws2_32.lib")
  8. using namespace std;
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12.     WSADATA wsa;
  13.     WORD Version = MAKEWORD (2 , 1);
  14.     WSAStartup(Version, &wsa);
  15.     SOCKET Listen = socket(AF_INET, SOCK_STREAM, NULL);
  16.     SOCKET Connect = socket(AF_INET, SOCK_STREAM, NULL);
  17.     SOCKADDR_IN Server;
  18.     Server.sin_addr.s_addr = inet_addr("127.0.0.1");
  19.     Server.sin_family = AF_INET;
  20.     Server.sin_port = htons(100);
  21.     bind(Listen, (SOCKADDR*)&Server, sizeof(Server));
  22.     listen(Listen, 1);
  23.     int size = sizeof(Server);
  24.     cout << "Listening...";
  25.     while(true){
  26.         if (Connect = accept(Listen, (SOCKADDR*)&Server , &size)){
  27.             cout << "\nConnectet! ";
  28.             break;
  29.         }
  30.            
  31.     }
  32.     WSACleanup();
  33.     cout << "Press the enter key to continue ...";
  34.     cin.get();
  35.     cin.get();
  36.     return EXIT_SUCCESS;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement