1 Star 1 Fork 0

Ves Mr / websockethttp-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
server_test.go 920 Bytes
一键复制 编辑 原始数据 按行查看 历史
Ves Mr 提交于 2022-05-13 22:14 . 简化代码
package websockethttp
import (
"log"
"net/http"
"testing"
)
func TestServer(t *testing.T) {
server := ServerNew("test-server")
server.ShowPongLogs(true)
server.SetAuthorizationFunc(func(request *http.Request) (string, bool) {
name := request.URL.Query().Get("name")
return name, len(name) > 2
})
server.RegisterProcessFunc("ServerTest", func(context *ServerContext) {
log.Printf("收到请求信息: %v", context.Request)
// 设置响应数据
context.Response.Code = 0
context.Response.Message = "ok"
context.Response.Body = "你好,这是服务器!"
})
server.AddConnOpenEventFunc(func(channel *ClientConnChannel) {
log.Printf("收到连接: %v", channel.ConnName)
channel.SendMessage("ClientTest", nil, "Hi client, conn ok !", func(context *ServerContext) {
log.Printf("收到响应信息: %v", context.Response.Body)
})
})
_ = server.LauncherServer("/websockethttp", 8080)
}
Go
1
https://gitee.com/vesmr/websockethttp-go.git
git@gitee.com:vesmr/websockethttp-go.git
vesmr
websockethttp-go
websockethttp-go
master

搜索帮助