• 8.5 使用Zinx-V0.8完成应用程序

    8.5 使用Zinx-V0.8完成应用程序

    测试代码和V0.6、V0.7的代码一样。因为Zinx框架对外接口没有发生改变。

    我们分别启动Server、Client

    1. $go run Server.go
    1. $go run Client0.go
    1. $go run Client1.go
    1. $go run Client0.go

    结果:

    服务端:

    1. $ go run Server.go
    2. Add api msgId = 0
    3. Add api msgId = 1
    4. [START] Server name: zinx v-0.8 demoApp,listenner at IP: 127.0.0.1, Port 7777 is starting
    5. [Zinx] Version: V0.4, MaxConn: 3, MaxPacketSize: 4096
    6. Worker ID = 4 is started.
    7. start Zinx server zinx v-0.8 demoApp succ, now listenning...
    8. Worker ID = 9 is started.
    9. Worker ID = 0 is started.
    10. Worker ID = 5 is started.
    11. Worker ID = 6 is started.
    12. Worker ID = 1 is started.
    13. Worker ID = 2 is started.
    14. Worker ID = 7 is started.
    15. Worker ID = 8 is started.
    16. Worker ID = 3 is started.
    17. Reader Goroutine is running
    18. Add ConnID= 0 request msgID= 0 to workerID= 0
    19. Call PingRouter Handle
    20. recv from client : msgId= 0 , data= Zinx V0.8 Client0 Test Message
    21. Reader Goroutine is running
    22. Add ConnID= 1 request msgID= 1 to workerID= 1
    23. Call HelloZinxRouter Handle
    24. recv from client : msgId= 1 , data= Zinx V0.8 Client1 Test Message
    25. Add ConnID= 0 request msgID= 0 to workerID= 0
    26. Call PingRouter Handle
    27. recv from client : msgId= 0 , data= Zinx V0.8 Client0 Test Message
    28. Reader Goroutine is running
    29. Add ConnID= 2 request msgID= 0 to workerID= 2
    30. Call PingRouter Handle
    31. recv from client : msgId= 0 , data= Zinx V0.8 Client0 Test Message
    32. Add ConnID= 1 request msgID= 1 to workerID= 1
    33. Call HelloZinxRouter Handle
    34. recv from client : msgId= 1 , data= Zinx V0.8 Client1 Test Message
    35. Add ConnID= 0 request msgID= 0 to workerID= 0
    36. Call PingRouter Handle
    37. recv from client : msgId= 0 , data= Zinx V0.8 Client0 Test Message
    38. Add ConnID= 2 request msgID= 0 to workerID= 2
    39. Call PingRouter Handle
    40. recv from client : msgId= 0 , data= Zinx V0.8 Client0 Test Message
    41. Add ConnID= 1 request msgID= 1 to workerID= 1
    42. Call HelloZinxRouter Handle
    43. recv from client : msgId= 1 , data= Zinx V0.8 Client1 Test Message
    44. Add ConnID= 0 request msgID= 0 to workerID= 0
    45. Call PingRouter Handle
    46. recv from client : msgId= 0 , data= Zinx V0.8 Client0 Test Message

    客户端0

    1. $ go run Client0.go
    2. Client Test ... start
    3. ==> Recv Msg: ID= 0 , len= 18 , data= ping...ping...ping
    4. ==> Recv Msg: ID= 0 , len= 18 , data= ping...ping...ping
    5. ==> Recv Msg: ID= 0 , len= 18 , data= ping...ping...ping
    6. ==> Recv Msg: ID= 0 , len= 18 , data= ping...ping...ping

    客户端1

    1. $ go run Client1.go
    2. Client Test ... start
    3. ==> Recv Msg: ID= 1 , len= 22 , data= Hello Zinx Router V0.8
    4. ==> Recv Msg: ID= 1 , len= 22 , data= Hello Zinx Router V0.8
    5. ==> Recv Msg: ID= 1 , len= 22 , data= Hello Zinx Router V0.8

    客户端2

    1. $ go run Client0.go
    2. Client Test ... start
    3. ==> Recv Msg: ID= 0 , len= 18 , data= ping...ping...ping
    4. ==> Recv Msg: ID= 0 , len= 18 , data= ping...ping...ping