|
|
@ -2,12 +2,12 @@ package znet |
|
|
|
|
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"net" |
|
|
|
"github.com/aceld/zinx/utils" |
|
|
|
"github.com/aceld/zinx/ziface" |
|
|
|
"net" |
|
|
|
) |
|
|
|
|
|
|
|
var zinx_logo = ` |
|
|
|
var zinxLogo = ` |
|
|
|
██ |
|
|
|
▀▀ |
|
|
|
████████ ████ ██▄████▄ ▀██ ██▀ |
|
|
@ -16,9 +16,9 @@ var zinx_logo = ` |
|
|
|
▄██▄▄▄▄▄ ▄▄▄██▄▄▄ ██ ██ ▄█▀▀█▄ |
|
|
|
▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀ ▀▀ ▀▀ ▀▀▀ ▀▀▀ |
|
|
|
` |
|
|
|
var top_line = `┌───────────────────────────────────────────────────┐` |
|
|
|
var border_line = `│` |
|
|
|
var bottom_line = `└───────────────────────────────────────────────────┘` |
|
|
|
var topLine = `┌───────────────────────────────────────────────────┐` |
|
|
|
var borderLine = `│` |
|
|
|
var bottomLine = `└───────────────────────────────────────────────────┘` |
|
|
|
|
|
|
|
//iServer 接口实现,定义一个Server服务类
|
|
|
|
type Server struct { |
|
|
@ -55,6 +55,7 @@ func NewServer () ziface.IServer { |
|
|
|
} |
|
|
|
return s |
|
|
|
} |
|
|
|
|
|
|
|
//============== 实现 ziface.IServer 里的全部接口方法 ========
|
|
|
|
|
|
|
|
//开启网络服务
|
|
|
@ -74,7 +75,7 @@ func (s *Server) Start() { |
|
|
|
} |
|
|
|
|
|
|
|
//2 监听服务器地址
|
|
|
|
listenner, err:= net.ListenTCP(s.IPVersion, addr) |
|
|
|
listener, err := net.ListenTCP(s.IPVersion, addr) |
|
|
|
if err != nil { |
|
|
|
fmt.Println("listen", s.IPVersion, "err", err) |
|
|
|
return |
|
|
@ -90,7 +91,7 @@ func (s *Server) Start() { |
|
|
|
//3 启动server网络连接业务
|
|
|
|
for { |
|
|
|
//3.1 阻塞等待客户端建立连接请求
|
|
|
|
conn, err := listenner.AcceptTCP() |
|
|
|
conn, err := listener.AcceptTCP() |
|
|
|
if err != nil { |
|
|
|
fmt.Println("Accept err ", err) |
|
|
|
continue |
|
|
@ -168,16 +169,13 @@ func (s *Server) CallOnConnStop(conn ziface.IConnection) { |
|
|
|
} |
|
|
|
|
|
|
|
func init() { |
|
|
|
fmt.Println(zinx_logo) |
|
|
|
fmt.Println(top_line) |
|
|
|
fmt.Println(fmt.Sprintf("%s [Github] https://github.com/aceld %s", border_line, border_line)) |
|
|
|
fmt.Println(fmt.Sprintf("%s [tutorial] https://www.jianshu.com/p/23d07c0a28e5 %s", border_line, border_line)) |
|
|
|
fmt.Println(bottom_line) |
|
|
|
fmt.Println(zinxLogo) |
|
|
|
fmt.Println(topLine) |
|
|
|
fmt.Println(fmt.Sprintf("%s [Github] https://github.com/aceld %s", borderLine, borderLine)) |
|
|
|
fmt.Println(fmt.Sprintf("%s [tutorial] https://www.jianshu.com/p/23d07c0a28e5 %s", borderLine, borderLine)) |
|
|
|
fmt.Println(bottomLine) |
|
|
|
fmt.Printf("[Zinx] Version: %s, MaxConn: %d, MaxPacketSize: %d\n", |
|
|
|
utils.GlobalObject.Version, |
|
|
|
utils.GlobalObject.MaxConn, |
|
|
|
utils.GlobalObject.MaxPacketSize) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|