本文整理汇总了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;
}
}
}
示例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;
}
}
}
}
示例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);
}
}
}
示例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;
}