diff --git a/examples/zinx_version_ex/ZinxV0.10Test/Client0.go b/examples/zinx_version_ex/ZinxV0.10Test/Client0.go index 103c75b..17923be 100644 --- a/examples/zinx_version_ex/ZinxV0.10Test/Client0.go +++ b/examples/zinx_version_ex/ZinxV0.10Test/Client0.go @@ -2,10 +2,11 @@ package main import ( "fmt" - "github.com/aceld/zinx/znet" "io" "net" "time" + + "github.com/aceld/zinx/znet" ) /* @@ -59,7 +60,7 @@ func main() { return } - fmt.Println("==> Recv Msg: ID=", msg.Id, ", len=", msg.DataLen, ", data=", string(msg.Data)) + fmt.Println("==> Recv Msg: ID=", msg.ID, ", len=", msg.DataLen, ", data=", string(msg.Data)) } time.Sleep(1 * time.Second) diff --git a/examples/zinx_version_ex/ZinxV0.10Test/Client1.go b/examples/zinx_version_ex/ZinxV0.10Test/Client1.go index c770a66..4aee73d 100644 --- a/examples/zinx_version_ex/ZinxV0.10Test/Client1.go +++ b/examples/zinx_version_ex/ZinxV0.10Test/Client1.go @@ -2,10 +2,11 @@ package main import ( "fmt" - "github.com/aceld/zinx/znet" "io" "net" "time" + + "github.com/aceld/zinx/znet" ) /* @@ -59,7 +60,7 @@ func main() { return } - fmt.Println("==> Recv Msg: ID=", msg.Id, ", len=", msg.DataLen, ", data=", string(msg.Data)) + fmt.Println("==> Recv Msg: ID=", msg.ID, ", len=", msg.DataLen, ", data=", string(msg.Data)) } time.Sleep(1 * time.Second) diff --git a/examples/zinx_version_ex/ZinxV0.11Test/Client0.go b/examples/zinx_version_ex/ZinxV0.11Test/Client0.go index 103c75b..17923be 100644 --- a/examples/zinx_version_ex/ZinxV0.11Test/Client0.go +++ b/examples/zinx_version_ex/ZinxV0.11Test/Client0.go @@ -2,10 +2,11 @@ package main import ( "fmt" - "github.com/aceld/zinx/znet" "io" "net" "time" + + "github.com/aceld/zinx/znet" ) /* @@ -59,7 +60,7 @@ func main() { return } - fmt.Println("==> Recv Msg: ID=", msg.Id, ", len=", msg.DataLen, ", data=", string(msg.Data)) + fmt.Println("==> Recv Msg: ID=", msg.ID, ", len=", msg.DataLen, ", data=", string(msg.Data)) } time.Sleep(1 * time.Second) diff --git a/examples/zinx_version_ex/ZinxV0.11Test/Client1.go b/examples/zinx_version_ex/ZinxV0.11Test/Client1.go index c770a66..4aee73d 100644 --- a/examples/zinx_version_ex/ZinxV0.11Test/Client1.go +++ b/examples/zinx_version_ex/ZinxV0.11Test/Client1.go @@ -2,10 +2,11 @@ package main import ( "fmt" - "github.com/aceld/zinx/znet" "io" "net" "time" + + "github.com/aceld/zinx/znet" ) /* @@ -59,7 +60,7 @@ func main() { return } - fmt.Println("==> Recv Msg: ID=", msg.Id, ", len=", msg.DataLen, ", data=", string(msg.Data)) + fmt.Println("==> Recv Msg: ID=", msg.ID, ", len=", msg.DataLen, ", data=", string(msg.Data)) } time.Sleep(1 * time.Second) diff --git a/examples/zinx_version_ex/ZinxV0.1Test/Server.go b/examples/zinx_version_ex/ZinxV0.1Test/Server.go index 99506db..4acdd71 100644 --- a/examples/zinx_version_ex/ZinxV0.1Test/Server.go +++ b/examples/zinx_version_ex/ZinxV0.1Test/Server.go @@ -11,7 +11,8 @@ func main() { 服务端测试 */ //1 创建一个server 句柄 s - s := znet.NewServer("[zinx V0.1]") + // s := znet.NewServer("[zinx V0.1]") + s := znet.NewServer() //2 开启服务 s.Serve() diff --git a/examples/zinx_version_ex/ZinxV0.2Test/Server.go b/examples/zinx_version_ex/ZinxV0.2Test/Server.go index 99506db..b0775a6 100644 --- a/examples/zinx_version_ex/ZinxV0.2Test/Server.go +++ b/examples/zinx_version_ex/ZinxV0.2Test/Server.go @@ -11,7 +11,9 @@ func main() { 服务端测试 */ //1 创建一个server 句柄 s - s := znet.NewServer("[zinx V0.1]") + // s := znet.NewServer("[zinx V0.2]") + + s := znet.NewServer() //2 开启服务 s.Serve() diff --git a/examples/zinx_version_ex/ZinxV0.3Test/Server.go b/examples/zinx_version_ex/ZinxV0.3Test/Server.go index 3cb1992..4203929 100644 --- a/examples/zinx_version_ex/ZinxV0.3Test/Server.go +++ b/examples/zinx_version_ex/ZinxV0.3Test/Server.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/aceld/zinx/ziface" "github.com/aceld/zinx/znet" ) @@ -40,10 +41,11 @@ func (this *PingRouter) PostHandle(request ziface.IRequest) { func main() { //创建一个server句柄 - s := znet.NewServer("[zinx V0.3]") - - s.AddRouter(&PingRouter{}) + // s := znet.NewServer("[zinx V0.3]") + s := znet.NewServer() + // s.AddRouter(&PingRouter{}) + s.AddRouter(3, &PingRouter{}) //2 开启服务 s.Serve() } diff --git a/examples/zinx_version_ex/ZinxV0.4Test/Server.go b/examples/zinx_version_ex/ZinxV0.4Test/Server.go index 9adb350..e9c597f 100644 --- a/examples/zinx_version_ex/ZinxV0.4Test/Server.go +++ b/examples/zinx_version_ex/ZinxV0.4Test/Server.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/aceld/zinx/ziface" "github.com/aceld/zinx/znet" ) @@ -43,7 +44,8 @@ func main() { s := znet.NewServer() //配置路由 - s.AddRouter(&PingRouter{}) + // s.AddRouter(&PingRouter{}) + s.AddRouter(4, &PingRouter{}) //开启服务 s.Serve() diff --git a/examples/zinx_version_ex/ZinxV0.5Test/Client.go b/examples/zinx_version_ex/ZinxV0.5Test/Client.go index a4769ad..94f2e0b 100644 --- a/examples/zinx_version_ex/ZinxV0.5Test/Client.go +++ b/examples/zinx_version_ex/ZinxV0.5Test/Client.go @@ -2,10 +2,11 @@ package main import ( "fmt" - "github.com/aceld/zinx/znet" "io" "net" "time" + + "github.com/aceld/zinx/znet" ) /* @@ -59,7 +60,7 @@ func main() { return } - fmt.Println("==> Recv Msg: ID=", msg.Id, ", len=", msg.DataLen, ", data=", string(msg.Data)) + fmt.Println("==> Recv Msg: ID=", msg.ID, ", len=", msg.DataLen, ", data=", string(msg.Data)) } time.Sleep(1 * time.Second) diff --git a/examples/zinx_version_ex/ZinxV0.5Test/Server.go b/examples/zinx_version_ex/ZinxV0.5Test/Server.go index e9f3e3f..39080a1 100644 --- a/examples/zinx_version_ex/ZinxV0.5Test/Server.go +++ b/examples/zinx_version_ex/ZinxV0.5Test/Server.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/aceld/zinx/ziface" "github.com/aceld/zinx/znet" ) @@ -35,7 +36,7 @@ func main() { s := znet.NewServer() //配置路由 - s.AddRouter(&PingRouter{}) + s.AddRouter(5, &PingRouter{}) //开启服务 s.Serve() diff --git a/examples/zinx_version_ex/ZinxV0.6Test-V0.7Test/Client0.go b/examples/zinx_version_ex/ZinxV0.6Test-V0.7Test/Client0.go index 1cf19ef..3a93964 100644 --- a/examples/zinx_version_ex/ZinxV0.6Test-V0.7Test/Client0.go +++ b/examples/zinx_version_ex/ZinxV0.6Test-V0.7Test/Client0.go @@ -2,10 +2,11 @@ package main import ( "fmt" - "github.com/aceld/zinx/znet" "io" "net" "time" + + "github.com/aceld/zinx/znet" ) /* @@ -59,7 +60,7 @@ func main() { return } - fmt.Println("==> Recv Msg: ID=", msg.Id, ", len=", msg.DataLen, ", data=", string(msg.Data)) + fmt.Println("==> Recv Msg: ID=", msg.ID, ", len=", msg.DataLen, ", data=", string(msg.Data)) } time.Sleep(1 * time.Second) diff --git a/examples/zinx_version_ex/ZinxV0.6Test-V0.7Test/Client1.go b/examples/zinx_version_ex/ZinxV0.6Test-V0.7Test/Client1.go index 02782f0..471d2f0 100644 --- a/examples/zinx_version_ex/ZinxV0.6Test-V0.7Test/Client1.go +++ b/examples/zinx_version_ex/ZinxV0.6Test-V0.7Test/Client1.go @@ -2,10 +2,11 @@ package main import ( "fmt" - "github.com/aceld/zinx/znet" "io" "net" "time" + + "github.com/aceld/zinx/znet" ) /* @@ -59,7 +60,7 @@ func main() { return } - fmt.Println("==> Recv Msg: ID=", msg.Id, ", len=", msg.DataLen, ", data=", string(msg.Data)) + fmt.Println("==> Recv Msg: ID=", msg.ID, ", len=", msg.DataLen, ", data=", string(msg.Data)) } time.Sleep(1 * time.Second) diff --git a/examples/zinx_version_ex/ZinxV0.8Test/Client0.go b/examples/zinx_version_ex/ZinxV0.8Test/Client0.go index 103c75b..17923be 100644 --- a/examples/zinx_version_ex/ZinxV0.8Test/Client0.go +++ b/examples/zinx_version_ex/ZinxV0.8Test/Client0.go @@ -2,10 +2,11 @@ package main import ( "fmt" - "github.com/aceld/zinx/znet" "io" "net" "time" + + "github.com/aceld/zinx/znet" ) /* @@ -59,7 +60,7 @@ func main() { return } - fmt.Println("==> Recv Msg: ID=", msg.Id, ", len=", msg.DataLen, ", data=", string(msg.Data)) + fmt.Println("==> Recv Msg: ID=", msg.ID, ", len=", msg.DataLen, ", data=", string(msg.Data)) } time.Sleep(1 * time.Second) diff --git a/examples/zinx_version_ex/ZinxV0.8Test/Client1.go b/examples/zinx_version_ex/ZinxV0.8Test/Client1.go index 4ef187b..792210c 100644 --- a/examples/zinx_version_ex/ZinxV0.8Test/Client1.go +++ b/examples/zinx_version_ex/ZinxV0.8Test/Client1.go @@ -2,10 +2,11 @@ package main import ( "fmt" - "github.com/aceld/zinx/znet" "io" "net" "time" + + "github.com/aceld/zinx/znet" ) /* @@ -59,7 +60,7 @@ func main() { return } - fmt.Println("==> Recv Msg: ID=", msg.Id, ", len=", msg.DataLen, ", data=", string(msg.Data)) + fmt.Println("==> Recv Msg: ID=", msg.ID, ", len=", msg.DataLen, ", data=", string(msg.Data)) } time.Sleep(1 * time.Second) diff --git a/examples/zinx_version_ex/ZinxV0.9Test/Client0.go b/examples/zinx_version_ex/ZinxV0.9Test/Client0.go index 103c75b..17923be 100644 --- a/examples/zinx_version_ex/ZinxV0.9Test/Client0.go +++ b/examples/zinx_version_ex/ZinxV0.9Test/Client0.go @@ -2,10 +2,11 @@ package main import ( "fmt" - "github.com/aceld/zinx/znet" "io" "net" "time" + + "github.com/aceld/zinx/znet" ) /* @@ -59,7 +60,7 @@ func main() { return } - fmt.Println("==> Recv Msg: ID=", msg.Id, ", len=", msg.DataLen, ", data=", string(msg.Data)) + fmt.Println("==> Recv Msg: ID=", msg.ID, ", len=", msg.DataLen, ", data=", string(msg.Data)) } time.Sleep(1 * time.Second) diff --git a/examples/zinx_version_ex/ZinxV0.9Test/Client1.go b/examples/zinx_version_ex/ZinxV0.9Test/Client1.go index c770a66..4aee73d 100644 --- a/examples/zinx_version_ex/ZinxV0.9Test/Client1.go +++ b/examples/zinx_version_ex/ZinxV0.9Test/Client1.go @@ -2,10 +2,11 @@ package main import ( "fmt" - "github.com/aceld/zinx/znet" "io" "net" "time" + + "github.com/aceld/zinx/znet" ) /* @@ -59,7 +60,7 @@ func main() { return } - fmt.Println("==> Recv Msg: ID=", msg.Id, ", len=", msg.DataLen, ", data=", string(msg.Data)) + fmt.Println("==> Recv Msg: ID=", msg.ID, ", len=", msg.DataLen, ", data=", string(msg.Data)) } time.Sleep(1 * time.Second) diff --git a/examples/zinx_version_ex/datapackDemo/Client.go b/examples/zinx_version_ex/datapackDemo/Client.go index 82df707..41b64de 100644 --- a/examples/zinx_version_ex/datapackDemo/Client.go +++ b/examples/zinx_version_ex/datapackDemo/Client.go @@ -2,8 +2,9 @@ package main import ( "fmt" - "github.com/aceld/zinx/znet" "net" + + "github.com/aceld/zinx/znet" ) func main() { @@ -19,7 +20,7 @@ func main() { //封装一个msg1包 msg1 := &znet.Message{ - Id: 0, + ID: 0, DataLen: 5, Data: []byte{'h', 'e', 'l', 'l', 'o'}, } @@ -31,7 +32,7 @@ func main() { } msg2 := &znet.Message{ - Id: 1, + ID: 1, DataLen: 7, Data: []byte{'w', 'o', 'r', 'l', 'd', '!', '!'}, } diff --git a/examples/zinx_version_ex/datapackDemo/Server.go b/examples/zinx_version_ex/datapackDemo/Server.go index c3b08e8..7c5a750 100644 --- a/examples/zinx_version_ex/datapackDemo/Server.go +++ b/examples/zinx_version_ex/datapackDemo/Server.go @@ -2,9 +2,10 @@ package main import ( "fmt" - "github.com/aceld/zinx/znet" "io" "net" + + "github.com/aceld/zinx/znet" ) //只是负责测试datapack拆包,封包功能 @@ -55,7 +56,7 @@ func main() { return } - fmt.Println("==> Recv Msg: ID=", msg.Id, ", len=", msg.DataLen, ", data=", string(msg.Data)) + fmt.Println("==> Recv Msg: ID=", msg.ID, ", len=", msg.DataLen, ", data=", string(msg.Data)) } } }(conn) diff --git a/utils/globalobj.go b/utils/globalobj.go index c64c640..9ec697d 100644 --- a/utils/globalobj.go +++ b/utils/globalobj.go @@ -2,10 +2,11 @@ package utils import ( "encoding/json" - "github.com/aceld/zinx/ziface" - "github.com/aceld/zinx/zlog" "io/ioutil" "os" + + "github.com/aceld/zinx/ziface" + "github.com/aceld/zinx/zlog" ) /* @@ -16,9 +17,9 @@ type GlobalObj struct { /* Server */ - TcpServer ziface.IServer //当前Zinx的全局Server对象 + TCPServer ziface.IServer //当前Zinx的全局Server对象 Host string //当前服务器主机IP - TcpPort int //当前服务器主机监听端口号 + TCPPort int //当前服务器主机监听端口号 Name string //当前服务器名称 /* @@ -49,7 +50,7 @@ type GlobalObj struct { */ var GlobalObject *GlobalObj -//判断一个文件是否存在 +//PathExists 判断一个文件是否存在 func PathExists(path string) (bool, error) { _, err := os.Stat(path) if err == nil { @@ -61,7 +62,7 @@ func PathExists(path string) (bool, error) { return false, err } -//读取用户的配置文件 +//Reload 读取用户的配置文件 func (g *GlobalObj) Reload() { if confFileExists, _ := PathExists(g.ConfFilePath); confFileExists != true { @@ -100,15 +101,15 @@ func init() { GlobalObject = &GlobalObj{ Name: "ZinxServerApp", Version: "V0.11", - TcpPort: 8999, + TCPPort: 8999, Host: "0.0.0.0", MaxConn: 12000, MaxPacketSize: 4096, - ConfFilePath: pwd+"/conf/zinx.json", + ConfFilePath: pwd + "/conf/zinx.json", WorkerPoolSize: 10, MaxWorkerTaskLen: 1024, MaxMsgChanLen: 1024, - LogDir: pwd+"/log", + LogDir: pwd + "/log", LogFile: "", LogDebugClose: false, } diff --git a/znet/connection.go b/znet/connection.go index d58d09d..a168942 100644 --- a/znet/connection.go +++ b/znet/connection.go @@ -162,10 +162,8 @@ func (c *Connection) Stop() { c.Lock() defer c.Unlock() - c.TCPServer.CallOnConnStop(c) - //如果当前链接已经关闭 if c.isClosed == true { return @@ -174,7 +172,7 @@ func (c *Connection) Stop() { fmt.Println("Conn Stop()...ConnID = ", c.ConnID) //如果用户注册了该链接的关闭回调业务,那么在此刻应该显示调用 - c.TcpServer.CallOnConnStop(c) + c.TCPServer.CallOnConnStop(c) // 关闭socket链接 c.Conn.Close() diff --git a/znet/server.go b/znet/server.go index 2bc0973..ac9ccf5 100644 --- a/znet/server.go +++ b/znet/server.go @@ -49,7 +49,7 @@ func NewServer() ziface.IServer { Name: utils.GlobalObject.Name, IPVersion: "tcp4", IP: utils.GlobalObject.Host, - Port: utils.GlobalObject.TcpPort, + Port: utils.GlobalObject.TCPPort, msgHandler: NewMsgHandle(), ConnMgr: NewConnManager(), }