设为首页 加入收藏

TOP

Muduo网络编程示例之四:Twisted Finger(二)
2014-11-23 22:04:05 来源: 作者: 【 】 浏览:12
Tags:Muduo 网络编程 示例 Twisted Finger
ssage(const TcpConnectionPtr& conn, 16: Buffer* buf, 17: Timestamp receiveTime) 18: { 19: const char* crlf = buf->findCRLF(); 20: if (crlf) 21: { 22: string user(buf->peek(), crlf); 23: conn->send(getUser(user) + " "); 24: buf->retrieveUntil(crlf + 2); 25: conn->shutdown(); 26: } 27: } 28: 29: int main() 30: { 31: users["schen"] = "Happy and well"; 32: EventLoop loop; 33: TcpServer server(&loop, InetAddress(1079), "Finger"); 34: server.setMessageCallback(onMessage); 35: server.start(); 36: loop.loop(); 37: }
以上就是全部内容,可以用 telnet 扮演客户端来测试我们的简单 finger 服务端。

Telnet 测试
在一个命令行窗口运行

$ ./bin/twisted_finger07

另一个命令行运行

$ telnet localhost 1079
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is ^].
muduo
No such user
Connection closed by foreign host.

再试一次

$ telnet localhost 1079
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is ^].
schen
Happy and well
Connection closed by foreign host.


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C语言--返回局部变量的地址 下一篇Muduo网络编程示例之三:定时器

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: