1、tcpserver

1         ServerSocket svs(6000);//绑定端口开始监听
2         TCPServer srv(new TCPServerConnectionFactoryImpl<EchoConnection>(), svs);
3         srv.start();

2、tcpclient

1      SocketAddress sa("localhost", svs.address().port());
2      StreamSocket ss1(sa);
3      ss1.sendBytes("hello", 5);
4      char buffer[256];
5      int n = ss1.receiveBytes(buffer, sizeof(buffer));
6      printf("n = %d\n",n);
7      ss1.close();

 

 

相关文章: