ifndef TCP_H #define TCP_H #pragma once #include <winsock2.h> #include <ws2tcpip.h> #include <iostream> #include "config.h" #include "tcp_packets.h" #include "change_ending.h" #include "md5.h" #pragma comment(lib, "Ws2_32.lib") class CTcpClient { private: char* szServerName; char* Port; SOCKET ConnectSocket; md5checksum Md5Var; public: int Size; bool Send(char* szMsg,int len); CTcpClient(char* servername,char* port) { Port=port; szServerName = servername; ConnectSocket = INVALID_SOCKET; Size=0; } bool Start(); void Stop(); // Free the resouces // Receive message from server char recvbuf[DEFAULT_BUFFER_PKT_LENGTH]; void Recv(); }; #endif // TCP_H
#include "tcp.h" #include "config.h" bool CTcpClient::Start() { WSADATA wsaData; // Initialize Winsock int iResult = WSAStartup(MAKEWORD(2,2), &wsaData); if(iResult != 0) { printf("WSAStartup failed: %d\n", iResult); return false; } struct addrinfo *result = NULL, *ptr = NULL, hints; ZeroMemory(&hints, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; //hints.ai_protocol = SOL_SOCKET; //Resolve the server address and port iResult = getaddrinfo(szServerName,Port, &hints, &result); if (iResult != 0) { printf("getaddrinfo failed: %d\n", iResult); WSACleanup(); return false; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)