Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DWORD WINAPI networkCl(void *userData)
- {
- char server[256] = {0};
- strcpy(server, (char*)userData);
- int iError = 0;
- struct addrinfo result;
- struct addrinfo hints;
- memset(&result, 0, sizeof(result));
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = AF_INET;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_protocol = IPPROTO_TCP;
- iError = getaddrinfo(server, "9904", &hints, (PADDRINFOA*)&result);
- if (iError != 0) { printf("getaddrinfo failed: %d\n", iError); WSACleanup(); return 0; }
- thisSock = INVALID_SOCKET;
- thisSock = socket(result.ai_family, result.ai_socktype, result.ai_protocol);
- if (thisSock == INVALID_SOCKET) { printf("socket failed: %d\n", WSAGetLastError()); WSACleanup(); return 1; }
- iError = connect(thisSock, result.ai_addr, (int)result.ai_addr);
- if (iError == SOCKET_ERROR) { printf("connect failed: %d\n", WSAGetLastError()); closesocket(thisSock); }
- if (thisSock == INVALID_SOCKET) { printf("unable to connect to server\n"); WSACleanup(); return 1; }
- DWORD WINAPI networkSv(void *userData)
- {
- int iError = 0;
- struct addrinfo result;
- struct addrinfo hints;
- memset(&result, 0, sizeof(result));
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = AF_INET;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_protocol = IPPROTO_TCP;
- hints.ai_flags = AI_PASSIVE;
- iError = getaddrinfo(NULL, "9904", &hints, (PADDRINFOA*)&result);
- if (iError != 0) { printf("getaddrinfo failed: %d\n", iError); WSACleanup(); return 0; }
- thisSock = INVALID_SOCKET;
- thisSock = socket(result.ai_family, result.ai_socktype, result.ai_protocol);
- if (thisSock == INVALID_SOCKET) { printf("socket failed: %d\n", WSAGetLastError()); WSACleanup(); return 1; }
- iError = bind(thisSock, result.ai_addr, (int)result.ai_addr);
- if (iError == SOCKET_ERROR) { printf("bind failed: %d\n", WSAGetLastError()); closesocket(thisSock); WSACleanup(); return 1; }
- if (listen(thisSock, SOMAXCONN) == SOCKET_ERROR)
- {
- printf("listen error: %d\n", WSAGetLastError());
- closesocket(thisSock);
- WSACleanup();
- return 1;
- }
- clSock = INVALID_SOCKET;
- clSock = accept(thisSock, NULL, NULL);
- if (clSock == INVALID_SOCKET)
- {
- printf("accept error: %d\n", WSAGetLastError());
- closesocket(thisSock);
- WSACleanup();
- return 1;
- }
Add Comment
Please, Sign In to add comment