Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions zconf/userconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ func UserConfToGlobal(config *Config) {
if config.WsPort != 0 {
GlobalObject.WsPort = config.WsPort
}
if config.WsPath != "" {
GlobalObject.WsPath = config.WsPath
}

if config.RouterSlicesMode {
GlobalObject.RouterSlicesMode = config.RouterSlicesMode
Expand Down
2 changes: 2 additions & 0 deletions zconf/zconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Config struct {
Host string // The IP address of the current server. (当前服务器主机IP)
TCPPort int // The port number on which the server listens for TCP connections.(当前服务器主机监听端口号)
WsPort int // The port number on which the server listens for WebSocket connections.(当前服务器主机websocket监听端口)
WsPath string // The path of the WebSocket connection.(websocket连接路径)
Name string // The name of the current server.(当前服务器名称)
KcpPort int // he port number on which the server listens for KCP connections.(当前服务器主机监听端口号)

Expand Down Expand Up @@ -219,6 +220,7 @@ func init() {
Version: "V1.0",
TCPPort: 8999,
WsPort: 9000,
WsPath: "/",
KcpPort: 9001,
Host: "0.0.0.0",
MaxConn: 12000,
Expand Down
7 changes: 5 additions & 2 deletions znet/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type Server struct {
Port int
// 服务绑定的websocket 端口 (Websocket port the server is bound to)
WsPort int
// 服务绑定的websocket 路径 (Websocket path the server is bound to)
WsPath string
// 服务绑定的kcp 端口 (kcp port the server is bound to)
KcpPort int

Expand Down Expand Up @@ -133,6 +135,7 @@ func newServerWithConfig(config *zconf.Config, ipVersion string, opts ...Option)
IP: config.Host,
Port: config.TCPPort,
WsPort: config.WsPort,
WsPath: config.WsPath,
KcpPort: config.KcpPort,
msgHandler: newMsgHandle(),
RouterSlicesMode: config.RouterSlicesMode,
Expand Down Expand Up @@ -311,8 +314,8 @@ func (s *Server) ListenTcpConn() {
}

func (s *Server) ListenWebsocketConn() {
zlog.Ins().InfoF("[START] WEBSOCKET Server name: %s,listener at IP: %s, Port %d is starting", s.Name, s.IP, s.WsPort)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
zlog.Ins().InfoF("[START] WEBSOCKET Server name: %s,listener at IP: %s, Port %d, Path %s is starting", s.Name, s.IP, s.WsPort, s.WsPath)
http.HandleFunc(s.WsPath, func(w http.ResponseWriter, r *http.Request) {
// 1. Check if the server has reached the maximum allowed number of connections
// (设置服务器最大连接控制,如果超过最大连接,则等待)
if s.ConnMgr.Len() >= zconf.GlobalObject.MaxConn {
Expand Down
Loading