ws
This commit is contained in:
@@ -32,8 +32,6 @@ func Init() {
|
|||||||
fmt.Printf("服务器启动成功,端口号:%s\n", CommonSetting.HttpPort)
|
fmt.Printf("服务器启动成功,端口号:%s\n", CommonSetting.HttpPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
var upgrader = websocket.Upgrader{}
|
|
||||||
|
|
||||||
func StartWebSocket(conn *websocket.Conn, clientID string, err error) {
|
func StartWebSocket(conn *websocket.Conn, clientID string, err error) {
|
||||||
|
|
||||||
//设置读取消息大小上线
|
//设置读取消息大小上线
|
||||||
|
|||||||
@@ -20,15 +20,21 @@ type IMController struct {
|
|||||||
// @Failure 200 {object} controllers.CallResult
|
// @Failure 200 {object} controllers.CallResult
|
||||||
// @router /StartWebSocket [get]
|
// @router /StartWebSocket [get]
|
||||||
func (c *IMController) StartWebSocket() {
|
func (c *IMController) StartWebSocket() {
|
||||||
upgrader.CheckOrigin = func(r *http.Request) bool {
|
|
||||||
return true
|
ws, err := upgrader.Upgrade(c.Ctx.ResponseWriter, &http.Request{
|
||||||
}
|
Method: "GET",
|
||||||
ws, err := upgrader.Upgrade(c.Ctx.ResponseWriter, c.Ctx.Request, nil)
|
Header: http.Header{
|
||||||
|
"Upgrade": []string{"websocket"},
|
||||||
|
"Connection": []string{"upgrade"},
|
||||||
|
"Sec-Websocket-Key": []string{"dGhlIHNhbXBsZSBub25jZQ=="},
|
||||||
|
"Sec-Websocket-Version": []string{"13"},
|
||||||
|
}}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
globals.SugarLogger.Errorf("upgrade error: %v", err)
|
globals.SugarLogger.Errorf("upgrade error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer ws.Close()
|
defer ws.Close()
|
||||||
|
|
||||||
clientID := c.GetString("clientID")
|
clientID := c.GetString("clientID")
|
||||||
globals.SugarLogger.Debugf("clientID=%s", clientID)
|
globals.SugarLogger.Debugf("clientID=%s", clientID)
|
||||||
im.StartWebSocket(ws, clientID, err)
|
im.StartWebSocket(ws, clientID, err)
|
||||||
|
|||||||
Reference in New Issue
Block a user