Browse Source

对ID和TCP命名进行修改同步

master
zhangjiyu 4 years ago
parent
commit
822fc0d08e
  1. 5
      examples/zinx_version_ex/ZinxV0.10Test/Client0.go
  2. 5
      examples/zinx_version_ex/ZinxV0.10Test/Client1.go
  3. 5
      examples/zinx_version_ex/ZinxV0.11Test/Client0.go
  4. 5
      examples/zinx_version_ex/ZinxV0.11Test/Client1.go
  5. 3
      examples/zinx_version_ex/ZinxV0.1Test/Server.go
  6. 4
      examples/zinx_version_ex/ZinxV0.2Test/Server.go
  7. 8
      examples/zinx_version_ex/ZinxV0.3Test/Server.go
  8. 4
      examples/zinx_version_ex/ZinxV0.4Test/Server.go
  9. 5
      examples/zinx_version_ex/ZinxV0.5Test/Client.go
  10. 3
      examples/zinx_version_ex/ZinxV0.5Test/Server.go
  11. 5
      examples/zinx_version_ex/ZinxV0.6Test-V0.7Test/Client0.go
  12. 5
      examples/zinx_version_ex/ZinxV0.6Test-V0.7Test/Client1.go
  13. 5
      examples/zinx_version_ex/ZinxV0.8Test/Client0.go
  14. 5
      examples/zinx_version_ex/ZinxV0.8Test/Client1.go
  15. 5
      examples/zinx_version_ex/ZinxV0.9Test/Client0.go
  16. 5
      examples/zinx_version_ex/ZinxV0.9Test/Client1.go
  17. 7
      examples/zinx_version_ex/datapackDemo/Client.go
  18. 5
      examples/zinx_version_ex/datapackDemo/Server.go
  19. 19
      utils/globalobj.go
  20. 4
      znet/connection.go
  21. 2
      znet/server.go

5
examples/zinx_version_ex/ZinxV0.10Test/Client0.go

@ -2,10 +2,11 @@ package main
import ( import (
"fmt" "fmt"
"github.com/aceld/zinx/znet"
"io" "io"
"net" "net"
"time" "time"
"github.com/aceld/zinx/znet"
) )
/* /*
@ -59,7 +60,7 @@ func main() {
return 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) time.Sleep(1 * time.Second)

5
examples/zinx_version_ex/ZinxV0.10Test/Client1.go

@ -2,10 +2,11 @@ package main
import ( import (
"fmt" "fmt"
"github.com/aceld/zinx/znet"
"io" "io"
"net" "net"
"time" "time"
"github.com/aceld/zinx/znet"
) )
/* /*
@ -59,7 +60,7 @@ func main() {
return 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) time.Sleep(1 * time.Second)

5
examples/zinx_version_ex/ZinxV0.11Test/Client0.go

@ -2,10 +2,11 @@ package main
import ( import (
"fmt" "fmt"
"github.com/aceld/zinx/znet"
"io" "io"
"net" "net"
"time" "time"
"github.com/aceld/zinx/znet"
) )
/* /*
@ -59,7 +60,7 @@ func main() {
return 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) time.Sleep(1 * time.Second)

5
examples/zinx_version_ex/ZinxV0.11Test/Client1.go

@ -2,10 +2,11 @@ package main
import ( import (
"fmt" "fmt"
"github.com/aceld/zinx/znet"
"io" "io"
"net" "net"
"time" "time"
"github.com/aceld/zinx/znet"
) )
/* /*
@ -59,7 +60,7 @@ func main() {
return 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) time.Sleep(1 * time.Second)

3
examples/zinx_version_ex/ZinxV0.1Test/Server.go

@ -11,7 +11,8 @@ func main() {
服务端测试 服务端测试
*/ */
//1 创建一个server 句柄 s //1 创建一个server 句柄 s
s := znet.NewServer("[zinx V0.1]")
// s := znet.NewServer("[zinx V0.1]")
s := znet.NewServer()
//2 开启服务 //2 开启服务
s.Serve() s.Serve()

4
examples/zinx_version_ex/ZinxV0.2Test/Server.go

@ -11,7 +11,9 @@ func main() {
服务端测试 服务端测试
*/ */
//1 创建一个server 句柄 s //1 创建一个server 句柄 s
s := znet.NewServer("[zinx V0.1]")
// s := znet.NewServer("[zinx V0.2]")
s := znet.NewServer()
//2 开启服务 //2 开启服务
s.Serve() s.Serve()

8
examples/zinx_version_ex/ZinxV0.3Test/Server.go

@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"github.com/aceld/zinx/ziface" "github.com/aceld/zinx/ziface"
"github.com/aceld/zinx/znet" "github.com/aceld/zinx/znet"
) )
@ -40,10 +41,11 @@ func (this *PingRouter) PostHandle(request ziface.IRequest) {
func main() { func main() {
//创建一个server句柄 //创建一个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 开启服务 //2 开启服务
s.Serve() s.Serve()
} }

4
examples/zinx_version_ex/ZinxV0.4Test/Server.go

@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"github.com/aceld/zinx/ziface" "github.com/aceld/zinx/ziface"
"github.com/aceld/zinx/znet" "github.com/aceld/zinx/znet"
) )
@ -43,7 +44,8 @@ func main() {
s := znet.NewServer() s := znet.NewServer()
//配置路由 //配置路由
s.AddRouter(&PingRouter{})
// s.AddRouter(&PingRouter{})
s.AddRouter(4, &PingRouter{})
//开启服务 //开启服务
s.Serve() s.Serve()

5
examples/zinx_version_ex/ZinxV0.5Test/Client.go

@ -2,10 +2,11 @@ package main
import ( import (
"fmt" "fmt"
"github.com/aceld/zinx/znet"
"io" "io"
"net" "net"
"time" "time"
"github.com/aceld/zinx/znet"
) )
/* /*
@ -59,7 +60,7 @@ func main() {
return 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) time.Sleep(1 * time.Second)

3
examples/zinx_version_ex/ZinxV0.5Test/Server.go

@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"github.com/aceld/zinx/ziface" "github.com/aceld/zinx/ziface"
"github.com/aceld/zinx/znet" "github.com/aceld/zinx/znet"
) )
@ -35,7 +36,7 @@ func main() {
s := znet.NewServer() s := znet.NewServer()
//配置路由 //配置路由
s.AddRouter(&PingRouter{})
s.AddRouter(5, &PingRouter{})
//开启服务 //开启服务
s.Serve() s.Serve()

5
examples/zinx_version_ex/ZinxV0.6Test-V0.7Test/Client0.go

@ -2,10 +2,11 @@ package main
import ( import (
"fmt" "fmt"
"github.com/aceld/zinx/znet"
"io" "io"
"net" "net"
"time" "time"
"github.com/aceld/zinx/znet"
) )
/* /*
@ -59,7 +60,7 @@ func main() {
return 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) time.Sleep(1 * time.Second)

5
examples/zinx_version_ex/ZinxV0.6Test-V0.7Test/Client1.go

@ -2,10 +2,11 @@ package main
import ( import (
"fmt" "fmt"
"github.com/aceld/zinx/znet"
"io" "io"
"net" "net"
"time" "time"
"github.com/aceld/zinx/znet"
) )
/* /*
@ -59,7 +60,7 @@ func main() {
return 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) time.Sleep(1 * time.Second)

5
examples/zinx_version_ex/ZinxV0.8Test/Client0.go

@ -2,10 +2,11 @@ package main
import ( import (
"fmt" "fmt"
"github.com/aceld/zinx/znet"
"io" "io"
"net" "net"
"time" "time"
"github.com/aceld/zinx/znet"
) )
/* /*
@ -59,7 +60,7 @@ func main() {
return 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) time.Sleep(1 * time.Second)

5
examples/zinx_version_ex/ZinxV0.8Test/Client1.go

@ -2,10 +2,11 @@ package main
import ( import (
"fmt" "fmt"
"github.com/aceld/zinx/znet"
"io" "io"
"net" "net"
"time" "time"
"github.com/aceld/zinx/znet"
) )
/* /*
@ -59,7 +60,7 @@ func main() {
return 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) time.Sleep(1 * time.Second)

5
examples/zinx_version_ex/ZinxV0.9Test/Client0.go

@ -2,10 +2,11 @@ package main
import ( import (
"fmt" "fmt"
"github.com/aceld/zinx/znet"
"io" "io"
"net" "net"
"time" "time"
"github.com/aceld/zinx/znet"
) )
/* /*
@ -59,7 +60,7 @@ func main() {
return 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) time.Sleep(1 * time.Second)

5
examples/zinx_version_ex/ZinxV0.9Test/Client1.go

@ -2,10 +2,11 @@ package main
import ( import (
"fmt" "fmt"
"github.com/aceld/zinx/znet"
"io" "io"
"net" "net"
"time" "time"
"github.com/aceld/zinx/znet"
) )
/* /*
@ -59,7 +60,7 @@ func main() {
return 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) time.Sleep(1 * time.Second)

7
examples/zinx_version_ex/datapackDemo/Client.go

@ -2,8 +2,9 @@ package main
import ( import (
"fmt" "fmt"
"github.com/aceld/zinx/znet"
"net" "net"
"github.com/aceld/zinx/znet"
) )
func main() { func main() {
@ -19,7 +20,7 @@ func main() {
//封装一个msg1包 //封装一个msg1包
msg1 := &znet.Message{ msg1 := &znet.Message{
Id: 0,
ID: 0,
DataLen: 5, DataLen: 5,
Data: []byte{'h', 'e', 'l', 'l', 'o'}, Data: []byte{'h', 'e', 'l', 'l', 'o'},
} }
@ -31,7 +32,7 @@ func main() {
} }
msg2 := &znet.Message{ msg2 := &znet.Message{
Id: 1,
ID: 1,
DataLen: 7, DataLen: 7,
Data: []byte{'w', 'o', 'r', 'l', 'd', '!', '!'}, Data: []byte{'w', 'o', 'r', 'l', 'd', '!', '!'},
} }

5
examples/zinx_version_ex/datapackDemo/Server.go

@ -2,9 +2,10 @@ package main
import ( import (
"fmt" "fmt"
"github.com/aceld/zinx/znet"
"io" "io"
"net" "net"
"github.com/aceld/zinx/znet"
) )
//只是负责测试datapack拆包,封包功能 //只是负责测试datapack拆包,封包功能
@ -55,7 +56,7 @@ func main() {
return 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) }(conn)

19
utils/globalobj.go

@ -2,10 +2,11 @@ package utils
import ( import (
"encoding/json" "encoding/json"
"github.com/aceld/zinx/ziface"
"github.com/aceld/zinx/zlog"
"io/ioutil" "io/ioutil"
"os" "os"
"github.com/aceld/zinx/ziface"
"github.com/aceld/zinx/zlog"
) )
/* /*
@ -16,9 +17,9 @@ type GlobalObj struct {
/* /*
Server Server
*/ */
TcpServer ziface.IServer //当前Zinx的全局Server对象
TCPServer ziface.IServer //当前Zinx的全局Server对象
Host string //当前服务器主机IP Host string //当前服务器主机IP
TcpPort int //当前服务器主机监听端口号
TCPPort int //当前服务器主机监听端口号
Name string //当前服务器名称 Name string //当前服务器名称
/* /*
@ -49,7 +50,7 @@ type GlobalObj struct {
*/ */
var GlobalObject *GlobalObj var GlobalObject *GlobalObj
//判断一个文件是否存在
//PathExists 判断一个文件是否存在
func PathExists(path string) (bool, error) { func PathExists(path string) (bool, error) {
_, err := os.Stat(path) _, err := os.Stat(path)
if err == nil { if err == nil {
@ -61,7 +62,7 @@ func PathExists(path string) (bool, error) {
return false, err return false, err
} }
//读取用户的配置文件
//Reload 读取用户的配置文件
func (g *GlobalObj) Reload() { func (g *GlobalObj) Reload() {
if confFileExists, _ := PathExists(g.ConfFilePath); confFileExists != true { if confFileExists, _ := PathExists(g.ConfFilePath); confFileExists != true {
@ -100,15 +101,15 @@ func init() {
GlobalObject = &GlobalObj{ GlobalObject = &GlobalObj{
Name: "ZinxServerApp", Name: "ZinxServerApp",
Version: "V0.11", Version: "V0.11",
TcpPort: 8999,
TCPPort: 8999,
Host: "0.0.0.0", Host: "0.0.0.0",
MaxConn: 12000, MaxConn: 12000,
MaxPacketSize: 4096, MaxPacketSize: 4096,
ConfFilePath: pwd+"/conf/zinx.json",
ConfFilePath: pwd + "/conf/zinx.json",
WorkerPoolSize: 10, WorkerPoolSize: 10,
MaxWorkerTaskLen: 1024, MaxWorkerTaskLen: 1024,
MaxMsgChanLen: 1024, MaxMsgChanLen: 1024,
LogDir: pwd+"/log",
LogDir: pwd + "/log",
LogFile: "", LogFile: "",
LogDebugClose: false, LogDebugClose: false,
} }

4
znet/connection.go

@ -162,10 +162,8 @@ func (c *Connection) Stop() {
c.Lock() c.Lock()
defer c.Unlock() defer c.Unlock()
c.TCPServer.CallOnConnStop(c) c.TCPServer.CallOnConnStop(c)
//如果当前链接已经关闭 //如果当前链接已经关闭
if c.isClosed == true { if c.isClosed == true {
return return
@ -174,7 +172,7 @@ func (c *Connection) Stop() {
fmt.Println("Conn Stop()...ConnID = ", c.ConnID) fmt.Println("Conn Stop()...ConnID = ", c.ConnID)
//如果用户注册了该链接的关闭回调业务,那么在此刻应该显示调用 //如果用户注册了该链接的关闭回调业务,那么在此刻应该显示调用
c.TcpServer.CallOnConnStop(c)
c.TCPServer.CallOnConnStop(c)
// 关闭socket链接 // 关闭socket链接
c.Conn.Close() c.Conn.Close()

2
znet/server.go

@ -49,7 +49,7 @@ func NewServer() ziface.IServer {
Name: utils.GlobalObject.Name, Name: utils.GlobalObject.Name,
IPVersion: "tcp4", IPVersion: "tcp4",
IP: utils.GlobalObject.Host, IP: utils.GlobalObject.Host,
Port: utils.GlobalObject.TcpPort,
Port: utils.GlobalObject.TCPPort,
msgHandler: NewMsgHandle(), msgHandler: NewMsgHandle(),
ConnMgr: NewConnManager(), ConnMgr: NewConnManager(),
} }

Loading…
Cancel
Save