快速启动

Docker方式

1、克隆项目

1
$ git clone https://github.com/aceld/zinx.git

2、进入服务端样例目录

1
$ cd ./zinx/examples/zinx_server

3、服务端编译

1
$ make build

4、服务端容器化

1
$ make image

5、服务端启动

1
$ make run

6、进入客户端样例目录

1
$ cd ../zinx_client

7、启动客户端进行测试

1
$ go run main.go

完整示例演示

1、 编译demo示例,会在zinx/example/zinx_server下得到server, 在zinx/example/zinx_client下得到client.

1
2
$ cd zinx/
$ make

2、 启动Demo server, 该终端不要关闭:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
$ cd example/zinx_server
$ ./server


██
▀▀
████████ ████ ██▄████▄ ▀██ ██▀
▄█▀ ██ ██▀ ██ ████
▄█▀ ██ ██ ██ ▄██▄
▄██▄▄▄▄▄ ▄▄▄██▄▄▄ ██ ██ ▄█▀▀█▄
▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀ ▀▀ ▀▀ ▀▀▀ ▀▀▀
┌───────────────────────────────────────────────────┐
│ [Github] https://github.com/aceld │
│ [tutorial] https://www.kancloud.cn/aceld/zinx │
└───────────────────────────────────────────────────┘
[Zinx] Version: V0.11, MaxConn: 3, MaxPacketSize: 4096
Add api msgId = 0
Add api msgId = 1


[START] Server name: zinx server Demo,listenner at IP: 127.0.0.1, Port 8999 is starting
Worker ID = 0 is started.
Worker ID = 1 is started.
Worker ID = 2 is started.
Worker ID = 3 is started.
Worker ID = 4 is started.
Worker ID = 7 is started.
Worker ID = 6 is started.
Worker ID = 8 is started.
Worker ID = 9 is started.
Worker ID = 5 is started.
start Zinx server zinx server Demo succ, now listenning...

1、 再打开新终端,启动client Demo测试通信

1
2
3
4
5
$ cd example/zinx_client
$ ./client
==> Test Router:[Ping] Recv Msg: ID= 2 , len= 21 , data= DoConnection BEGIN... ==> Test Router:[Ping] Recv Msg: ID= 0 , len= 18 , data= ping...ping...ping
==> Test Router:[Ping] Recv Msg: ID= 0 , len= 18 , data= ping...ping...ping
==> Test Router:[Ping] Recv Msg: ID= 0 , len= 18 , data= ping...ping...ping