Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Server
- #include <cstdio>
- #include <cstdlib>
- #include <winsock2.h>
- #include <iostream>
- using namespace std;
- int main()
- {
- //WinSock Startup
- WSAData wsaData;
- WORD DLLVerion = MAKEWORD(2, 1);
- if (WSAStartup(DLLVerion, &wsaData) != 0) //if wsastartup returns anything other than 0, then that means an error has
- {
- MessageBoxA(NULL, "Winsock startup failed", "Error", MB_OK | MB_ICONERROR);
- exit(1);
- }
- SOCKADDR_IN addr; //Address that we will bind our listening socket to
- int addrlen = sizeof(addr); //Length of the addres (required for accept call)
- 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 */
- addr.sin_port = htons(1111); //port
- addr.sin_family = AF_INET; //IPv4 Socket
- SOCKET sListen = socket(AF_INET, SOCK_STREAM, NULL); //Create socket to listen for new conections
- bind(sListen, (SOCKADDR*)&addr, sizeof(addr)); //Bind he addess to the socket
- listen(sListen, SOMAXCONN); //PLaces sListen socket in a state in which it is listening for an inconing conections
- SOCKET newConnection; // Socket to hold the client's connection
- newConnection = accept(sListen, (SOCKADDR*)&addr, &addrlen); //accept a new connection
- if (newConnection == 0) //if accepting rhe client connection failed
- {
- std::cout << "Failed to accept the client's connection." << std::endl;
- }
- else
- {
- std::cout << "Client Connected!!" << std::endl;
- }
- system("pasue");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement