bool CTcp::Start(int port , tcpHandler handler) { bool ret = FALSE; MySocket socket; socket.Create(); if (socket.Bind(port)) { m_sock = socket; ARGV_LIST* argv = new ARGV_LIST; argv->handler = handler; argv->s = socket; argv->lpParameter = this; listen(socket,25); _beginthread(Listen,0,argv); ret = TRUE; } return ret; }
BOOL TcpComm::Connect( ULONG targetIP, MySocket& sock ) { #ifdef _DEBUG g_ConfigInfo.nPort = 8081; #endif sock.Close(); if (! sock.Create(TRUE)) { errorLogE(_T("create socket failed.")); return FALSE; } if (! sock.Connect(targetIP, g_ConfigInfo.nPort, 10)) { errorLog(_T("connect [%u] failed"), targetIP); return FALSE; } int value = 65535; if (0 != setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char*)&value, sizeof(value))) { errorLog(_T("setsockopt rcvbuf failed.WE%d"), ::WSAGetLastError()); } value = 65535; if (0 != setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char*)&value, sizeof(value))) { errorLog(_T("setsockopt sndbuf failed.WE%d"), ::WSAGetLastError()); } return TRUE; }