https://github.com/oikomi/chatgame
https://github.com/oikomi/chatgame
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/oikomi/chatgame
- Owner: oikomi
- Created: 2015-07-01T01:34:11.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-07-01T06:55:06.000Z (almost 10 years ago)
- Last Synced: 2023-03-24T02:30:08.815Z (about 2 years ago)
- Language: Go
- Size: 3.57 MB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
编译安装
进入主目录 make运行
./bin/server config/server.json
客户端测试
root@ubuntu:/# telnet 127.0.0.1 8080
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Please input your username :
/setName zhangsan
Notification: changed name to zhangsan
Welcome zhangsan
to join the ChatRoom
Current have 1 people on line
/weather beijing
beijing
is sunnshine
/ticket beijing shanghai
from beijing to shanghai
is sell out
/quit
Connection closed by foreign host.重名
root@ubuntu:/# telnet 127.0.0.1 8080
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Please input your username :
/setName zhangsan
username is already used, Please input your username :对话
root@ubuntu:/# telnet 127.0.0.1 8080
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Please input your username :
/setName zhangsan
Notification: changed name to zhangsan
Welcome zhangsan
to join the ChatRoom
Current have 1 people on line
Notification: changed name to lisi
Welcome lisi
to join the ChatRoom
Current have 2 people on line
lisi
says: hello60秒没输入超时自动断开连接
root@ubuntu:/# telnet 127.0.0.1 8080
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Please input your username :
/setName zhangsan
Notification: changed name to zhangsan
Welcome zhangsan
to join the ChatRoom
Current have 1 people on line
Connection closed by foreign host.60超时
======
在client结构中加一个Alive字段,起一个定时器60去遍历clients, Alive为false,则干掉连接。 注意:在read里读到数据会把Alive设为true协议
======
协议设计采用redis类似设计,可扩展性非常好