Titan Panda
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with
67 additions and
47 deletions
-
examples/zinx_version_ex/ZinxV0.10Test/Client0.go
-
examples/zinx_version_ex/ZinxV0.10Test/Client1.go
-
examples/zinx_version_ex/ZinxV0.11Test/Client0.go
-
examples/zinx_version_ex/ZinxV0.11Test/Client1.go
-
examples/zinx_version_ex/ZinxV0.1Test/Server.go
-
examples/zinx_version_ex/ZinxV0.2Test/Server.go
-
examples/zinx_version_ex/ZinxV0.3Test/Server.go
-
examples/zinx_version_ex/ZinxV0.4Test/Server.go
-
examples/zinx_version_ex/ZinxV0.5Test/Client.go
-
examples/zinx_version_ex/ZinxV0.5Test/Server.go
-
examples/zinx_version_ex/ZinxV0.6Test-V0.7Test/Client0.go
-
examples/zinx_version_ex/ZinxV0.6Test-V0.7Test/Client1.go
-
examples/zinx_version_ex/ZinxV0.8Test/Client0.go
-
examples/zinx_version_ex/ZinxV0.8Test/Client1.go
-
examples/zinx_version_ex/ZinxV0.9Test/Client0.go
-
examples/zinx_version_ex/ZinxV0.9Test/Client1.go
-
examples/zinx_version_ex/datapackDemo/Client.go
-
examples/zinx_version_ex/datapackDemo/Server.go
-
utils/globalobj.go
-
znet/connection.go
-
znet/server.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) |
|
|
|
|
|
@ -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) |
|
|
|
|
|
@ -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) |
|
|
|
|
|
@ -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) |
|
|
|
|
|
@ -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() |
|
|
|
|
|
@ -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() |
|
|
|
|
|
@ -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() |
|
|
|
} |
|
|
@ -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() |
|
|
|
|
|
@ -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) |
|
|
|
|
|
@ -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() |
|
|
|
|
|
@ -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) |
|
|
|
|
|
@ -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) |
|
|
|
|
|
@ -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) |
|
|
|
|
|
@ -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) |
|
|
|
|
|
@ -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) |
|
|
|
|
|
@ -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) |
|
|
|
|
|
@ -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', '!', '!'}, |
|
|
|
} |
|
|
|
|
|
@ -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) |
|
|
|
|
|
@ -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,7 +101,7 @@ func init() { |
|
|
|
GlobalObject = &GlobalObj{ |
|
|
|
Name: "ZinxServerApp", |
|
|
|
Version: "V0.11", |
|
|
|
TcpPort: 8999, |
|
|
|
TCPPort: 8999, |
|
|
|
Host: "0.0.0.0", |
|
|
|
MaxConn: 12000, |
|
|
|
MaxPacketSize: 4096, |
|
|
|
|
|
@ -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() |
|
|
|
|
|
@ -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(), |
|
|
|
} |
|
|
|