smallchat$ ls Makefile README.md smallchat smallchat.c
直接启动服务端二进制文件即可
1
./smallchat 127.0.0.1 7711
聊天
端口
服务端默认端口是7771。当然你也可以修改重新编译成自己想要的端口
1
#define SERVER_PORT 7711
终端
终端1
1 2 3 4 5 6 7 8 9 10
telnet 127.0.0.1 7711 Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is '^]'. Welcome to Simple Chat! Use /nick <nick> to set your nick. #设置客户端昵称 /nick 你的昵称 /nick tinywan001
#发送消息 This is just a programming example (tinywan001)
图片
终端2
1 2 3 4 5 6 7 8 9 10 11
telnet 127.0.0.1 7711 Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is '^]'. Welcome to Simple Chat! Use /nick <nick> to set your nick.
# 设置客户端昵称 /nick 你的昵称 /nick tinywan002
# 发送消息 Since I wrote this little program (tinywan002)
服务端
1 2 3 4 5 6 7 8 9 10 11 12
./smallchat Connected client fd=4 Connected client fd=5 tinywan002> Since I wrote this little program (tinywan002) tinywan001> This is just a programming example (tinywan001) tinywan001> 001 tinywan002> 002 tinywan002> 002002002 tinywan001> 001001001001