本文整理汇总了C++中TcpSocket::getRemoteAddress方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpSocket::getRemoteAddress方法的具体用法?C++ TcpSocket::getRemoteAddress怎么用?C++ TcpSocket::getRemoteAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TcpSocket
的用法示例。
在下文中一共展示了TcpSocket::getRemoteAddress方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tcpSocketTest
bool SocketTest::tcpSocketTest()
{
SimpleServer server;
server.start();
System::Sleep(500);
TEST_ASSERT(server.start_flag)
TEST_ASSERT_MSG(server.bind_flag, server.msg.text())
TEST_ASSERT_MSG(!server.aborted, server.msg.text())
// create tcp socket
TcpSocket client;
client.connect(TCP_TEST_HOST, TCP_TEST_PORT);
TEST_ASSERT(client.getRemoteAddress().getPort() == TCP_TEST_PORT);
client.send(TEST_MESSAGE1);
TEST_ASSERT_MSG(!server.aborted, server.msg.text())
System::Sleep(100);
TEST_ASSERT_MSG(!server.aborted, server.msg.text())
TEST_ASSERT(server.msg1_flag)
// test if something is already running on a port
Socket psocket;
TEST_THROWS(psocket.bind(TCP_TEST_PORT), Net::Errors::SocketException);
String in;
client.readUntil(in, '!');
TEST_ASSERT(in == TEST_MESSAGE2);
client.readUntil(in, '.', 2000);
TEST_ASSERT_MSG(in == TEST_MESSAGE3, in.text());
client.readUntil(in, '!', 2000);
TEST_ASSERT(in == TEST_MESSAGE4);
client.readUntil(in, "#@", 2000);
TEST_ASSERT(in == TEST_MESSAGE5);
return true;
}
示例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;
}