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


C++ TCPSocket::destIpAndPort方法代码示例

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


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

示例1: run

void LoginManager::run() {
	_running = true;

	while (_running) {
		MultipleTCPSocketsListener multipleSocketsListener;

		vector<TCPSocket*> sockets;
		for (map<std::string, TCPSocket*>::iterator iter = _pendingPeers.begin(); iter != _pendingPeers.end(); iter++) {
			sockets.push_back(iter->second);
		}

		multipleSocketsListener.addSockets(sockets);

		TCPSocket* readySock = multipleSocketsListener.listenToSocket(2);
		if (readySock == NULL) {
			continue;
		}

		string username;
		string password;

		int command = MessengerServer::readCommandFromPeer(readySock);
		switch (command) {
		case LOGIN_REQUEST:
			username = MessengerServer::readDataFromPeer(readySock);
			password = MessengerServer::readDataFromPeer(readySock);
			if (login(username, password, readySock)) {
				MessengerServer::sendCommandToPeer(readySock, LOGIN_REQUEST_APPROVED);
			} else {
				if (_messengerServer->isLoggedIn(username)) { // Already logged in
					MessengerServer::sendCommandToPeer(readySock, LOGIN_REQUEST_ALREADY_LOGGED);
				} else {
					MessengerServer::sendCommandToPeer(readySock, LOGIN_REQUEST_WRONG_DETAILS);
				}
			}
			break;

		case REGISTRATION_REQUEST:
			username = MessengerServer::readDataFromPeer(readySock);
			password = MessengerServer::readDataFromPeer(readySock);
			if (signUp(username, password)) {
				MessengerServer::sendCommandToPeer(readySock, REGISTRATION_REQUEST_APPROVED);
			} else {
				MessengerServer::sendCommandToPeer(readySock, REGISTRATION_REQUEST_DENIED);
			}
			break;

		case EXIT:
			_pendingPeers.erase(readySock->destIpAndPort());
			cout << "Peer disconnected: " + readySock->destIpAndPort() << endl;
			break;
		}
	}
}
开发者ID:Dewnisan,项目名称:Messenger-App,代码行数:54,代码来源:LoginManager.cpp

示例2: run

void Dispatcher::run()
{
  while(1)
  {
	  TCPSocket* speaker = multiListener->listenToSocket(10);
	  if(speaker!=NULL)
	  {
	  int cmd;
	  speaker->recv((char*)&cmd,4);
	  cmd = ntohl(cmd);
	  switch(cmd)
		  {
	      case SESSION_ESTABLISHED:
		      cout<<"connected";
	    	  break;

		  case OPEN_SESSION_WITH_PEER:
			  {string dest = ReceiveMsg(speaker);
			   ConnectRequest(speaker->destIpAndPort(),dest);}
			   break;

		  case USER_LIST:
			   sendUserList(speaker);
			   break;

		  case ROOM_LIST:
			   sendRoomList(speaker);
			   break;

		  case MEMBERS_LIST:
			  {string room = ReceiveMsg(speaker);
			   sendMembersList(speaker,room);}
			   break;

		  case CREATE_CHAT:
			   SetActiveChat(speaker->destIpAndPort());
			   break;

		  case CLOSE_CHAT:
			   CloseUserChat(speaker->destIpAndPort());
			   break;

		  case CLOSE_SESSION_WITH_PEER:
			   closePeer(speaker->destIpAndPort());
			   break;

		  default:
		  break;
		 }
	   }
   }
}
开发者ID:alexnakr,项目名称:Client-server-chat---C-,代码行数:52,代码来源:Dispatcher.cpp

示例3: run

void MsaTcpServer::run()
{
	_dispatcher->start();

	while(true)
	{
		TCPSocket* newPeer = _serverSock->listenAndAccept();
		if (newPeer!= NULL)
		{
			cout<<"Add Peer"<<newPeer->destIpAndPort()<<endl;
			_dispatcher->addPeer(newPeer);
		}

	}
}
开发者ID:nivg1992,项目名称:FinalProjectNetworkingColman,代码行数:15,代码来源:MsaTcpServer.cpp

示例4: run

void Listener::run() {
	_running = true;

	while (_running) {
		TCPSocket* sock = _listenSock->listenAndAccept();
		if (sock == NULL) {
			break;
		}

		struct timeval timeout;
		timeout.tv_sec = 720;
		timeout.tv_usec = 0;

		setsockopt(sock->getSocketFid(), SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof timeout);

		_loginManager->addPendingPeer(sock);
		cout << "New peer connected: " << sock->destIpAndPort() << endl;
	}

	cout << "Listener has stopped" << endl;
}
开发者ID:Dewnisan,项目名称:Messenger-App,代码行数:21,代码来源:Listener.cpp


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