本文整理汇总了C++中TcpSocket::getLocalPort方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpSocket::getLocalPort方法的具体用法?C++ TcpSocket::getLocalPort怎么用?C++ TcpSocket::getLocalPort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TcpSocket
的用法示例。
在下文中一共展示了TcpSocket::getLocalPort方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: acceptConnections
void TcpHandler::acceptConnections()
{
TcpSocket* client = new TcpSocket();
if (_listener.accept(*client) != Socket::Done)
{
printf("Listening failed. \n");
return;
}
printf("New connection on port: ");
client->setBlocking(false);
std::cout<<client->getLocalPort()<<std::endl;
_mutex.lock();
_connectedClients.push_back(client);
_mutex.unlock();
}
示例2: main
int main()
{
TcpServer server;
if (server.listen(2000) != AbstractSocket::Done)
{
perror("Error :");
return -1;
}
TcpSocket* s = server.accept();
if (s == NULL)
{
cout << "Error: cannot accept conection" << endl;
return -1;
}
cout << "Connected client" << endl;
int i = 4;
i++;
cout << "Remote host : " << s->getRemotePort() << endl;
cout << s->getLocalPort() << endl;
cout << server.getRemoteAddress().toString() << endl;
cout << s->getRemoteAddress().toString() << endl;
s->sendInt32(10);
sleep(2);
s->sendString("hello");
s->sendCharArray("world", 5);
Frame f;
f << "This is a frame " << 666 << '\n';
if (s->sendFrame(f) != AbstractSocket::Done)
perror("error on send frame");
delete s;
server.close();
s->close();
return 1;
}