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


C++ ConnectToServer函数代码示例

本文整理汇总了C++中ConnectToServer函数的典型用法代码示例。如果您正苦于以下问题:C++ ConnectToServer函数的具体用法?C++ ConnectToServer怎么用?C++ ConnectToServer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: ConnectToServer

bool	NetworkMoudle::Connect(const char* strIP,int nPort)				// 连接到服务器
{
	m_strIP = strIP;
	m_nServerPort = nPort;
	m_bIsConnect = ConnectToServer(strIP,nPort);
	return m_bIsConnect;
}
开发者ID:mobinsheng,项目名称:Fighting,代码行数:7,代码来源:NetworkMoudle.cpp

示例2: Start

BOOL CTcpClient::Start(LPCTSTR pszRemoteAddress, USHORT usPort, BOOL bAsyncConnect)
{
	if(!CheckParams() || !CheckStarting())
		return FALSE;

	BOOL isOK		= FALSE;
	m_bAsyncConnect	= bAsyncConnect;

	if(CreateClientSocket())
	{
		if(FirePrepareConnect(m_dwConnID, m_soClient) != HR_ERROR)
		{
			if(ConnectToServer(pszRemoteAddress, usPort))
			{
				if(CreateWorkerThread())
					isOK = TRUE;
				else
					SetLastError(SE_WORKER_THREAD_CREATE, __FUNCTION__, ERROR_CREATE_FAILED);
			}
			else
				SetLastError(SE_CONNECT_SERVER, __FUNCTION__, ::WSAGetLastError());
		}
		else
			SetLastError(SE_SOCKET_PREPARE, __FUNCTION__, ERROR_FUNCTION_FAILED);
	}
	else
		SetLastError(SE_SOCKET_CREATE, __FUNCTION__, ::WSAGetLastError());

	if(!isOK) Stop();

	return isOK;
}
开发者ID:cxc3214,项目名称:HP-Socket,代码行数:32,代码来源:TcpClient.cpp

示例3: RAS_SendActionResponse

/*****************************************************************************//**
* @brief This function sets up the PUT response to the remote server after
*    the GET response is returned.
*
* @param status.  The status of the query.
* @param msg.  Result code to be sent back to the remote server.
* @param id.  id of action
* @return nothing.
* @author Neal Shurmantine
* @version
* 02/09/2016    Created.
*******************************************************************************/
uint32_t RAS_SendActionResponse(eActionStatus status, eActionMessageId msg, uint32_t action_id)
{
    REST_CLIENT_QUERY_STRUCT_PTR p_query = (REST_CLIENT_QUERY_STRUCT_PTR)OS_GetMemBlock(sizeof(REST_CLIENT_QUERY_STRUCT));
    char *clientJSON = (char*)OS_GetMemBlock(MAX_JSON_LENGTH);

    LoadDefaultClientData(p_query, &hunterDouglasRASServerSSLParameters,HTTPSRV_REQ_PUT,put_action_response_return);

    snprintf(clientJSON,MAX_JSON_LENGTH, HUB_ACTION_JSON_RESPONSE, status, msg);
    snprintf(p_query->resource,MAX_RESOURCE_NAME_LENGTH, HUB_ACTION_PUT_RESOURCE, RMT_GetAPIVersion(), action_id);

    p_query->json = clientJSON;

    p_query->socket_options.connection_timeout = 18 * SEC_IN_MS;

    MakeAuthorizationString(p_query->authorize,false);

    ConnectToServer(p_query);
    if (p_query->connection.socket) {
        if (PutResource(p_query,false)) {
            p_query->callback(p_query);
        }
        DisconnectFromServer(p_query);
    }
    OS_ReleaseMemBlock((char*)clientJSON);
    OS_ReleaseMemBlock((void*)p_query);
    return 1;
}
开发者ID:ShurfireSoftware,项目名称:Simple,代码行数:39,代码来源:RAS_RemoteActionServer.c

示例4: assert

void TServerConnectState::Update(nel::TGameTime deltaTime)
{
	TGameState::Update(deltaTime);

	IClient* client = (IClient*)Application->RetrieveInterface(IID_IClient);
	assert(client);
	client->Process();

	switch (progress)
	{
		case SHOULDCONNECT:		
			ConnectToServer();
			progress = CONNECTING;
			break;
		case CONNECTING:	
			if (client->IsConnected()) 
				progress = CONNECTED; 
			break;
		case CONNECTED:
			if (client->IsInLobby())
			{
				progress = INLOBBY;
				Owner->SetNextState(SID_Lobby);
			}
			break;
		case INLOBBY:			
			break;
	};
}
开发者ID:frevan,项目名称:Neuronic-Bomberman,代码行数:29,代码来源:serverconnect.cpp

示例5: ConnectToServer

//-----------------------------------------------------------------------------
// Purpose: 
//
//-----------------------------------------------------------------------------
void CUISelectServer::PressOKBtn()
{
	// 서버군과 서버가 선택되었으면 접속 시도.
	int	nSelServerGroup = m_lbServerGroup.GetCurSel();
	int	nSelServer = m_lbServer.GetCurSel();
	if( nSelServerGroup != -1 && nSelServer != -1 )
	{
		sServerInfo &SI = m_vectorGroupInfo[nSelServerGroup].vectorServerInfo[nSelServer];
								
		// 서버에 연결을 시도합니다.
		if( SI.iPlayerNum < _cmiComm.cci_iFullUsers )
		{
			_pSound->Mute();
			if(_pNetwork->m_iServerGroup != m_vectorGroupInfo[nSelServerGroup].iServerNo)
			{
				CUIManager* pUIManager = CUIManager::getSingleton();
				pUIManager->GetRankingViewEx()->ClearRankingList();
			}
			_pNetwork->m_iServerGroup = m_vectorGroupInfo[nSelServerGroup].iServerNo;
			_pNetwork->m_iServerCh = SI.iSubNum;		// UI_REFORM :Su-won

			ConnectToServer( SI.strAddress, SI.iPortNum );

			_pGameState->ClearCharacterSlot();
			
#ifdef RESTRICT_SOUND
			extern BOOL _bNTKernel;
			//if( _bNTKernel )
				_pSound->UpdateSounds();
			#endif
		}
	}
}
开发者ID:RocketersAlex,项目名称:LCSource,代码行数:37,代码来源:UISelectServer.cpp

示例6: _tmain

int _tmain(int argc, _TCHAR* argv[])
{
    bool isConnected = false;
    do
    {
        std::cout << "Press enter to connect" << std::endl;
        std::cin.get();
        ConnectSocket = ConnectToServer();
        if (ConnectSocket != INVALID_SOCKET)
        {
            std::cout << "Success, begin input" << std::endl;
            isConnected = true;
            DWORD threadId;
            HANDLE tread = CreateThread(
                               NULL,
                               0,
                               ReceiveData,
                               NULL,
                               0,
                               &threadId);
        }
    }
    while (!isConnected);
    while (ConnectSocket != INVALID_SOCKET)
    {
        std::cin.getline(bufferSend, BUFFER_SIZE);
        SendData(ConnectSocket, bufferSend);
    }
    return 0;
}
开发者ID:Gambrinius,项目名称:Laboratory-code,代码行数:30,代码来源:KSiSLab2ChatClient.cpp

示例7: InitCommClient

BOOL InitCommClient( SOCK *clnt, const char *address, unsigned short serverPortNr, unsigned short clientPortNr, int timeOutMS )
{ BOOL fatal, ret = FALSE;
  int err;
	if( InitIP() && CreateClient( clnt, clientPortNr, TRUE ) ){
		QTils_LogMsgEx( "Client socket opened on port %hu", clientPortNr );
		if( ConnectToServer( *clnt, serverPortNr, "", address, timeOutMS, &fatal ) ){
			QTils_LogMsgEx( "Connected to server \"%s:%hu\"", address, serverPortNr );
			if( !SendMutex ){
				SendMutex = new CritSectEx(4000);
			}
			if( !ReceiveMutex ){
				ReceiveMutex = new CritSectEx(4000);
			}
			ret = TRUE;
		}
		else{
			err = errSock;
			QTils_LogMsgEx( "Failure connecting to server \"%s:%hu\" (err=%d \"%s\")",
						address, serverPortNr, err, errSockText(err) );
			CloseClient(clnt);
		}
	}
	else{
		QTils_LogMsgEx( "Failure opening client socket on port %hu (err=%d \"%s\")",
					clientPortNr, errSock, errSockText(errSock) );
	}
	return ret;
}
开发者ID:RJVB,项目名称:QTilities,代码行数:28,代码来源:QTVODcomm.cpp

示例8: InitServerConnection

DWORD CMMThread::StartThread(ST_THREADS_PARAM *pstThreadsParam)
{
	ST_THREADS_PARAM stThreadParam = *pstThreadsParam;

	ST_SERVER_ADDR stServerAddr;
	stServerAddr.strIPAddress = stThreadParam.strIPAddress;
	stServerAddr.dwPort = stThreadParam.dwPort;

	InitServerConnection(stServerAddr);

	BOOL bConnected = FALSE;
	BOOL bContinue = TRUE;
	while (bContinue) 
	{
		try
		{
			if (!bConnected) {
				bConnected = ConnectToServer();
			}

			ProcessCycleTask(stThreadParam);
		}
		catch (std::exception &e) {
			ErrorLog("%s", e.what());
			::WSACleanup();
		}

		// Wait for 1 second for a next step
		::Sleep(1000);
	}
	
	::WSACleanup();
	return E_RET_SUCCESS;
}
开发者ID:timewizhan,项目名称:MSProject,代码行数:34,代码来源:MMThread.cpp

示例9: OnTimerProc

VOID WINAPI OnTimerProc(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
	switch (idEvent)
	{
		case _ID_TIMER_KEEPALIVE:
		{
			if (g_csock != INVALID_SOCKET)
			{
				SendExToServer(PACKET_KEEPALIVE);
				SendMessage(g_hStatusBar, SB_SETTEXT, MAKEWORD(2, 0), (LPARAM)_TEXT("Check Activity"));
			}

			break;
		}
		case _ID_TIMER_CONNECTSERVER:
		{
			if (g_csock == INVALID_SOCKET)
			{
				DWORD	dwIP = 0;
				int		nPort = 0;

				InsertLogMsg(IDS_APPLY_RECONNECT);

				jRegGetKey(_SELGATE_SERVER_REGISTRY, _TEXT("RemoteIP"), (LPBYTE)&dwIP);

				if (!jRegGetKey(_SELGATE_SERVER_REGISTRY, _TEXT("RemotePort"), (LPBYTE)&nPort))
					nPort = 5000;

				ConnectToServer(g_csock, &g_caddr, _IDM_CLIENTSOCK_MSG, NULL, dwIP, nPort, FD_CONNECT|FD_READ|FD_CLOSE);
			}

			break;
		}
	}
}
开发者ID:KaSt,项目名称:mir2ei,代码行数:35,代码来源:ThreadFuncForComm.cpp

示例10: Execute

//---------------------------------------------------------------------------
void __fastcall TSendThread::Execute()
{
	SOCKET ConnectSocket;
	int r;

	User = LoginForm->UserEdit->Text;
	Password = LoginForm->PasswordEdit->Text;

	if (ConnectSocket = ConnectToServer(this,  ms, srv))	{
		if (Auth(this, ConnectSocket))	{
			r = XMLFile(this, ConnectSocket, msXML);
			if (r) {
				SendForm->Close();
				ThreadMsg = "Данные успешно переданы.";
				Synchronize(&ShowThreadMessage);
			}
		}
		ShutDownConnection(this, ConnectSocket);
	}
	if (SendForm->Visible == true) {
		ThreadMsg = "Ошибка при передаче данных. Данные не отправлены.";
		Synchronize(&ShowThreadMessage);
	}

	delete msXML;
//	delete ms;
//    SendForm->Close();
	//---- Place thread code here ----
}
开发者ID:IshPeredysh,项目名称:udd,代码行数:30,代码来源:TSendThread.cpp

示例11: PutDoubleData

int PutDoubleData(char *cmdsbuf, short cmds_length, 
				  char *fnamebuf, short fname_length)
{

	int fd, __attribute__ ((unused)) result2;
	char buf[IPCCMDLEN];
	IPCU ipc;

	if( (fd = ConnectToServer()) == -1 )
		return -1;

	// Write "FDATA" command first.
	strcpy(buf, "WDATA");
	result2 = write(fd, buf, IPCCMDLEN);

	// Prepare for ipc union, then copy buffer data.
	ipc.fncmds.cmdslen = (long)cmds_length;
	ipc.fncmds.filenamelen = (long)fname_length;
	memcpy(ipc.fncmds.cmds, cmdsbuf, cmds_length);
	memcpy(ipc.fncmds.filename, fnamebuf, fname_length);
	result2 = write(fd, &ipc, sizeof(IPCU));

	close(fd);
	return 0;
}
开发者ID:dbnicholson,项目名称:cnijfilter-common,代码行数:25,代码来源:ipcproc.c

示例12: _T

HRESULT CHttpDownloader::WorkFunction()
{
	HRESULT hr;
	_bstr_t strBuffer;
	
	strBuffer = _T("");

	if(m_longAbort > 0)
	{
		hr = E_ABORT;
		goto EndWorkFunc;
	}

	if(m_request.pCritSect)
		EnterCriticalSection(m_request.pCritSect);
	
	if(m_longAbort > 0)
	{
		hr = E_ABORT;
		goto EndWorkFunc;
	}

	hr = ConnectToServer(strBuffer);
	if(FAILED(hr))
		goto EndWorkFunc;

	hr = ReadData(strBuffer);
	if(FAILED(hr) || m_dwDownloaded < m_dwTotalSize)
	{
		strBuffer = _T("Cannot read data");
		goto EndWorkFunc;
	}
	
EndWorkFunc:

//	TRACE(_T("HTTP OPERATION = %d\n"), m_context.op);

	Clear();
	
	if(m_pStream)
	{
		LARGE_INTEGER li = {0, 0};
		hr = m_pStream->Seek(li, STREAM_SEEK_SET, NULL);
	}
	
	if(m_request.pCritSect)
	{
		try
		{
			LeaveCriticalSection(m_request.pCritSect);
		}
		catch(...)
		{
//			MCTRACE(0, _T("LeaveCriticalSection(%08x)"), m_request.pCritSect);
		}
	}
	
	return hr;
}
开发者ID:0anion0,项目名称:IBN,代码行数:59,代码来源:HttpDownloader.cpp

示例13: Run

cf_void Run()
{
    cf_fd severfd =ServerType::CreateListenSocket(DBPROXYSERVER_PORT);

    std::vector < pthread_t > tids_network;
    pthread_t tid =0;
    // net thread pool.
    for(int i=0; i<g_numPipe; i++)
    {
        int rt =pthread_create(&tid,NULL,ThreadNetwork,(void *)&severfd);
        if(0!=rt)
        {
            printf("pthread_create error,error=%s \n",strerror(errno));
            break;
        }
        tids_network.push_back(tid);
        g_tid_pipe[tid] =i;
    }

    g_inQueue =new TYPE_Queue[g_numPipe];
    g_outQueue =new TYPE_Queue[g_numPipe]; 

    std::vector < pthread_t > tids_dbaccess;
    // db access thread pool.
    for(int i=0; i<g_numPipe*g_threadsCntPerPipe; i++)
    {
        int rt =pthread_create(&tid,NULL,ThreadDBAccess,NULL);
        if(0!=rt)
        {
            printf("pthread_create error,error=%s \n",strerror(errno));
            break;
        }
        tids_dbaccess.push_back(tid);
        ConnectToServer("127.0.0.1",DBPROXYSERVER_PORT);
        g_tid_fd[tid] =-1;
        printf("-- %u->%d g_tid_fd.size()=%u--- \n",(cf_uint32)tid,-1,(cf_uint32)(g_tid_fd.size()));
    }
    
    
    for(int i=0; i<int(tids_network.size()); i++)
    {
        int rt = pthread_join(tids_network[i], NULL);
        if(0!=rt)
        {
            printf("pthread_join error,error=%s \n",strerror(errno));
            break;
        }
    }
    for(int i=0; i<int(tids_dbaccess.size()); i++)
    {
        int rt = pthread_join(tids_dbaccess[i], NULL);
        if(0!=rt)
        {
            printf("pthread_join error,error=%s \n",strerror(errno));
            break;
        }
    }
}
开发者ID:object8421,项目名称:publicdoc,代码行数:58,代码来源:db_proxy_server.cpp

示例14: ConnectToServer

BOOL JsonServer::MaintainConnection()
{
	if (m_bShutdown) {
		return TRUE;
	}

	if ( m_pLoginServerSession ) {
		if ( m_pLoginServerSession->TryToConnect() ) {
			ConnectToServer( m_pLoginServerSession, (char *)m_pLoginServerSession->GetConnnectIP().c_str(), m_pLoginServerSession->GetConnnectPort() );
		}
	}
	
	if ( m_pDBServerSession ) {
		if ( m_pDBServerSession->TryToConnect() ) {
			ConnectToServer( m_pDBServerSession, (char *)m_pDBServerSession->GetConnnectIP().c_str(), m_pDBServerSession->GetConnnectPort() );
		}
	}
}
开发者ID:syalr,项目名称:login_public,代码行数:18,代码来源:JsonServer.cpp

示例15: Run

BOOL CDPMonitorClient::Run( LPCSTR lpAddr, u_long uPort, DWORD dwMonitorId, BOOL fsndPing )
{
	if( FALSE == ConnectToServer( lpAddr, uPort, FALSE ) )
		return FALSE;

	BEFORESEND( ar, PACKETTYPE_MONITOR_ID );
	ar << dwMonitorId << fsndPing;
	SEND( ar, this, DPID_SERVERPLAYER );

	return TRUE;
}
开发者ID:iceberry,项目名称:flyffsf,代码行数:11,代码来源:dpmonitorclient.cpp


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