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


C++ CClientSocket类代码示例

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


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

示例1: HandleClients

// Handle all our clients
void CServerSocket::HandleClients( fd_set* fds )
{
    for(UINT i=0;i<ClientList.size( );i++)
	{
        CClientSocket* client = ClientList.at( i );
        if(!client->isActive)
            continue;
		if(FD_ISSET( client->sock, fds ))
		{
            if (client->isserver == true)
            {
               //Log( MSG_INFO,"ISC PACKET");
               if(!client->ISCThread()){
               client->isActive = false;
               DisconnectClient( client );}
            }
            else
			if(!client->ReceiveData( ) )
			{
                client->isActive = false;
                DisconnectClient( client ); 
			}
		}
	}  
}
开发者ID:RavenX8,项目名称:osirose,代码行数:26,代码来源:SocketServer.cpp

示例2: main

int main(int argc ,char *argv[])
{
	char *addr = NULL;
	int port;
	if(argc == 1)
	{
		addr = "127.0.0.1";
		port = 8800;
	}else if(argc == 2){
		addr = argv[1];
		port = 8800;
	}else if(argc == 3){
		addr = argv[1];
		port = atoi(argv[2]);
	}else{
		cout<<"error:"<<argv[0]<<" ipaddress portnumber"<<endl;
		return -1;
	}

	CClientSocket *ccs = new CClientSocket(addr, port);

	ccs->startThread();
	
	ccs->joinHost();
	
	delete ccs;

	return 0;
}
开发者ID:passedaway,项目名称:misc,代码行数:29,代码来源:c.cpp

示例3: TcpAccept

int CServerSocket::TcpAccept(CClientSocket& socket)
{
  struct sockaddr_in client;
  socklen_t clientlen = sizeof(client);

  if (m_sock == -1)
  {
    m_error = "socket closed";
    return FAIL;
  }

  int returnv = WaitForSocket(false, "Accept");  //wait for socket to become readable
  if (returnv == FAIL || returnv == TIMEOUT)
    return returnv;
  
  int sock = accept(m_sock, reinterpret_cast<struct sockaddr*>(&client), &clientlen);
  if (sock < 0)
  {
    m_error = "accept() " + GetErrno();
    return FAIL;
  }

  if (socket.SetInfo(inet_ntoa(client.sin_addr), ntohs(client.sin_port), sock) != SUCCESS)
  {
    m_error = socket.GetError();
    return FAIL;
  }
  
  return SUCCESS;
}
开发者ID:Nash2001,项目名称:boblight-for-enigma2,代码行数:30,代码来源:sockets.cpp

示例4: memset

void CClientSocket::UpdateUserOline(CString strUserInfo,char from[20])
 {
	 HEADER head;
	 head.type = MSG_UPDATE;
	 head.SendLen = strUserInfo.GetLength()*2;
	 memset(head.from, 0, sizeof(head.from));
	 memset(head.beizhu,0,sizeof(head.beizhu));
	 memset(head.to,0,sizeof(head.to));
	 strcpy(head.from,from);
	 char *pSend = new char[head.SendLen];
	 memset(pSend, 0, head.SendLen);

	 if( !WChar2MByte(strUserInfo.GetBuffer(0), pSend, head.SendLen))
	 {
		 AfxMessageBox(_T("用户全部退出!"));
		 delete pSend;
		 return;
	 }
	POSITION pss = m_List->GetHeadPosition();  //循环对客户端发送消息
	while(pss!=NULL)
	{
		 CClientSocket* pTemp = (CClientSocket*)m_List->GetNext(pss);
		//发送协议头
		pTemp->Send((char*)&head, sizeof(head));
		pTemp->Send(pSend,head.SendLen ); 
	}	
	delete pSend;
 }
开发者ID:ITnull,项目名称:ChatRoom,代码行数:28,代码来源:ClientSocket.cpp

示例5: WorkThread

DWORD WINAPI CClientSocket::WorkThread(LPVOID lparam)   
{
	CClientSocket *pThis = (CClientSocket *)lparam;
	char	buff[MAX_RECV_BUFFER];
	fd_set fdSocket;
	FD_ZERO(&fdSocket);
	FD_SET(pThis->m_Socket, &fdSocket);
	while (pThis->IsRunning())
	{
		fd_set fdRead = fdSocket;
		int nRet = select(NULL, &fdRead, NULL, NULL, NULL);
		if (nRet == SOCKET_ERROR)
		{
			pThis->Disconnect();
			break;
		}
		if (nRet > 0)
		{
			memset(buff, 0, sizeof(buff));
			int nSize = recv(pThis->m_Socket, buff, sizeof(buff), 0);
			if (nSize <= 0)
			{
				pThis->Disconnect();
				break;
			}
			if (nSize > 0) pThis->OnRead((LPBYTE)buff, nSize);
		}
	}

	return -1;
}
开发者ID:pr1n4ple,项目名称:TwiceClient,代码行数:31,代码来源:ClientSocket.cpp

示例6: 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

示例7: SetAppState

void CClientDlg::OnBnClickedStop()
{
	SetAppState(ST_STOPING);

	for(size_t i = 0; i < m_vtClients.Size(); i++)
	{
		CClientSocket* pSocket = m_vtClients[i];

		if(pSocket->Stop())
			::LogClientStop((DWORD)i + 1);
		else
			ASSERT(FALSE);
	}

	::WaitWithMessageLoop(100L);

	CString strMsg;
	strMsg.Format(	_T(" *** Summary: expect -  %lld, send - %lld, recv - %lld"),
					m_llExpectReceived, m_llTotalSent, m_llTotalReceived);

	::LogMsg(strMsg);

	if(m_llExpectReceived == m_llTotalSent && m_llTotalSent == m_llTotalReceived)
		strMsg.Format(_T(" *** Success: time consuming -  %u millisecond !"), m_dwTimeconsuming);
	else
		strMsg.Format(_T(" *** Fail: manual terminated ? (or data lost)"));

	::LogMsg(strMsg);

	SetAppState(ST_STOPED);
}
开发者ID:xiongleiFTD,项目名称:TestSocket,代码行数:31,代码来源:ClientDlg.cpp

示例8: 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

示例9: CClientSocket

void CServer::incomingConnection(int handle)
{
    CClientSocket *client = new CClientSocket();
    //client->SetSocket(handle);
    client->SetSocket(handle);

    connect(client,SIGNAL(sendSignal(saveStruct&)),this,SLOT(sendMessage(saveStruct&)));
    connect(client,SIGNAL(deleteSignal(QString&)),this,SLOT(disconnect(QString&)));
}
开发者ID:huddy1985,项目名称:ChatOnline,代码行数:9,代码来源:cserver.cpp

示例10: sl

void CServerSocket::OnAccept(int nErrorCode)
{
	CSingleLock sl(&m_csClientLock, TRUE);

	if( nErrorCode != 0 )
	{
		TRACE("CServerSocket::OnAccept Error : %d\n", ::WSAGetLastError());
	}
	else
	{
		// 빈 클라이언트를 찾는다
		long nClientID = -1;
		long nMaxClient = (long)m_vecnbClientUsed.size();
		for(long i = 0; i < nMaxClient; i++)
		{
			if(m_vecnbClientUsed[i] == FALSE)
			{
				nClientID = i;
				break;
			}
		}
		if(nClientID != -1)
		{
			if(m_vecpClient[nClientID] == NULL)
				m_vecpClient[nClientID] = new CClientSocket;

			CClientSocket *pCurSocket = m_vecpClient[nClientID];
			pCurSocket->InitClient(m_nClientStartID + nClientID, m_hParentWnd, m_bUseReceiveCallback, m_pParentPtr, __CallbackDataReceive);
			m_vecnbClientUsed[nClientID] = TRUE;
			m_vecpClient[nClientID]->m_bConnect = TRUE;
			Accept(*pCurSocket, NULL, NULL);

			TRACE("CServerSocket::OnAccept\n");
			if(m_hParentWnd)
				::PostMessage(m_hParentWnd, UWM_SOCKET_UPDATE_CONNECTION, nClientID, EVT_CONSUCCESS);
			else
				__CallbackDataReceive(m_pParentPtr, nClientID, (BYTE *) - 1, EVT_CONSUCCESS);
		}
		else
		{
			CSocket Socket;
			Accept(Socket, NULL, NULL);
			Socket.ShutDown();
			Socket.Close();
		}
	}

	CAsyncSocket::OnAccept(nErrorCode);
}
开发者ID:songyunsang,项目名称:personal_only,代码行数:49,代码来源:ServerSocket.cpp

示例11: Accept

/**
 * @brief Acepta conexiones entrantes
 *
 * @return En caso de no poder aceptar ninguna conexión, devolverá false. Si se puede aceptar una conexión entrante,
 * devolverá true.
 *
 * Se intentará entablar una conexión con un cliente remoto por medio de la función SDLNet_TCP_Accept().
 * Si todo va bien, se entablará la conexión.
 */
bool CHostSocket::Accept (CClientSocket& the_client_socket) {
    TCPsocket cs;
    if ((cs = SDLNet_TCP_Accept(m_Socket))) {
        the_client_socket.SetSocket(cs);
        return true;
    }
    else
        return false;
}
开发者ID:wikiti,项目名称:ullPong,代码行数:18,代码来源:CNet.cpp

示例12: CloseClientSocket

void CServerSocket::CloseClientSocket(long nClientID)
{
	if(m_vecnbClientUsed[nClientID] != TRUE)
		return;
	if(m_vecpClient[nClientID] == NULL)
		return;

	CClientSocket *pCurClient = m_vecpClient[nClientID];
	pCurClient->ShutDown();
	pCurClient->Close();

	delete pCurClient;
	pCurClient = nullptr;

	m_vecpClient[nClientID] = NULL;
	m_vecnbClientUsed[nClientID] = FALSE;

	TRACE("CServerSocket::CloseClientSocket\n");
}
开发者ID:songyunsang,项目名称:personal_only,代码行数:19,代码来源:ServerSocket.cpp

示例13: 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

示例14: Accept

bool CHostSocket::Accept(CClientSocket& clientSocket)
{
	TCPsocket clientSock;
	
	if((clientSock = SDLNet_TCP_Accept(_socket)))
	{
		clientSocket.SetSocket(clientSock);
		return true;
	}
	else{return false;}
}
开发者ID:skakri09,项目名称:FrozenEngine--as-delivered---school-,代码行数:11,代码来源:TCPsocketHost.cpp

示例15: strcpy

void CClientSocket::MSGTranslate(char* buff,int nlen,char to[20],char from[20],char beizhu[20])
{
	 HEADER head;
	 head.type = MSG_SEND;
	 head.SendLen = nlen;
	 strcpy(head.to,to);
	 strcpy(head.from,from);
	 memset(head.beizhu,0,20);

	 POSITION ps = m_List->GetHeadPosition();  //取得,所有用户的队列
	 CString str(buff);
	 int i =  strcmp(head.to,"群聊");
	 while(ps!=NULL)
	 {
		CClientSocket* pTemp = (CClientSocket*)m_List->GetNext(ps);
		//实现群聊和一对一关键就在于此
		if(pTemp->m_strName==head.to || pTemp->m_strName==head.from || i==0 )
		{
			pTemp->Send(&head,sizeof(HEADER));  //先发送头部
			pTemp->Send(buff, nlen);			//再发送内容
		}
	 }
}
开发者ID:ITnull,项目名称:ChatRoom,代码行数:23,代码来源:ClientSocket.cpp


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