Advertisement
Guest User

HELP PLS

a guest
May 3rd, 2016
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. //Server
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <winsock2.h>
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     //WinSock Startup
  12.     WSAData wsaData;
  13.     WORD DLLVerion = MAKEWORD(2, 1);
  14.     if (WSAStartup(DLLVerion, &wsaData) != 0) //if wsastartup returns anything other than 0, then that means an error has
  15.     {
  16.         MessageBoxA(NULL, "Winsock startup failed", "Error", MB_OK | MB_ICONERROR);
  17.         exit(1);
  18.     }
  19.  
  20.     SOCKADDR_IN addr; //Address that we will bind our listening socket to
  21.     int addrlen = sizeof(addr); //Length of the addres (required for accept call)
  22.     addr.sin_addr.s_addr = inet_addr("127.0.0.1"); /* <----------------------- THIS LINE HAVE PROBLEM LOG -> Error  1   error C4996: 'inet_addr': Use inet_pton() or InetPton() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings    c:\users\adrian\documents\visual studio 2013\projects\test_dzialania\test_dzialania\source.cpp  22  1   Test_dzialania  */
  23.  
  24.  
  25.  
  26.     addr.sin_port = htons(1111); //port
  27.     addr.sin_family = AF_INET; //IPv4 Socket
  28.  
  29.     SOCKET sListen = socket(AF_INET, SOCK_STREAM, NULL); //Create socket to listen for new conections
  30.     bind(sListen, (SOCKADDR*)&addr, sizeof(addr)); //Bind he addess to the socket
  31.     listen(sListen, SOMAXCONN); //PLaces sListen socket in a state in which it is listening for an inconing conections
  32.  
  33.     SOCKET newConnection; // Socket to hold the client's connection
  34.     newConnection = accept(sListen, (SOCKADDR*)&addr, &addrlen); //accept a new connection
  35.  
  36.     if (newConnection == 0) //if accepting rhe client connection failed
  37.     {
  38.         std::cout << "Failed to accept the client's connection." << std::endl;
  39.     }
  40.     else
  41.     {
  42.         std::cout << "Client Connected!!" << std::endl;
  43.     }
  44.     system("pasue");
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement