TCPServer要用TCP的客户端来测试。POCO中TCP方式的Socket有:
Poco::Net::ServerSocket
Poco::Net::StreamSocket
Poco::Net::DialogSocket
Poco::Net::SecureServerSocket ---相对于SSL
Poco::Net::SecureStreamSocket ---相对于SSL
1 ServerSocket svs(0); 2 TCPServer srv(new TCPServerConnectionFactoryImpl<EchoConnection>(), svs); 3 srv.start(); 4 SocketAddress sa("localhost", svs.address().port()); 5 StreamSocket ss1(sa); 6 std::string data("hello, world"); 7 ss1.sendBytes(data.data(), (int) data.size()); 8 char buffer[256]; 9 int n = ss1.receiveBytes(buffer, sizeof(buffer)); 10 cout<<"n = "<<n<<endl; 11 ss1.close();
1 EchoServer echoServer; 2 DialogSocket ds; 3 ds.connect(SocketAddress("localhost",echoServer.port())); 4 ds.sendMessage("Hello,world!"); 5 std::string str; 6 ds.receiveMessage(str); 7 cout<<"str = "<<str<<endl; 8 9 ds.sendMessage("KAREN","appinf.com"); 10 ds.receiveMessage(str); 11 cout<<"str = "<<str<<endl; 12 13 ds.sendMessage("220 Hello, world!"); 14 int status = ds.receiveStatusMessage(str); 15 cout<<"status = "<<status<<endl; 16 17 ds.sendString("220-line1\r\n220 line2\r\n"); 18 status = ds.receiveStatusMessage(str); 19 cout<<"status = "<<status<<endl; 20 cout<<"str = "<<str<<endl;