完成基本的server启动以及example
This commit is contained in:
54
example/server.go
Normal file
54
example/server.go
Normal file
@ -0,0 +1,54 @@
|
||||
// Package main ...
|
||||
//
|
||||
// Description : 启动一个ws server 的示例
|
||||
//
|
||||
// Author : go_developer@163.com<张德满>
|
||||
//
|
||||
// Date : 2021-03-28 3:57 下午
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-developer/websocket"
|
||||
"github.com/go-developer/websocket/abstract"
|
||||
"github.com/go-developer/websocket/context"
|
||||
)
|
||||
|
||||
func main() {
|
||||
websocket.NewWebsocketServe(&Example{})
|
||||
}
|
||||
|
||||
type Example struct {
|
||||
}
|
||||
|
||||
func (e Example) Connect(ctx *context.WSContext) {
|
||||
fmt.Println("建立连接成功")
|
||||
}
|
||||
|
||||
func (e Example) Disconnect(ctx *context.WSContext) {
|
||||
fmt.Println("断开连接成功")
|
||||
}
|
||||
|
||||
func (e Example) Close(ctx *context.WSContext, code int, message string) error {
|
||||
fmt.Println("关闭连接成功")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e Example) HandshakeURL() []string {
|
||||
return []string{
|
||||
"/ws/test",
|
||||
}
|
||||
}
|
||||
|
||||
func (e Example) GetCommandList() []abstract.ICommand {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e Example) GetModuleFlag() string {
|
||||
return "example"
|
||||
}
|
||||
|
||||
func (e Example) GetServerPort() int {
|
||||
return 10099
|
||||
}
|
Reference in New Issue
Block a user