dpxyfa4718 2016-01-28 06:56
浏览 116

在大猩猩网络套接字中获得``意外的EOF''

I have the following read pump for a gorilla websockets connection in Go.

func (c *connection) readPump() {

//function to close the websocket
defer func() {
    socketsHub.unregister <- c
    c.ws.Close()
}()

c.ws.SetReadLimit(maxMessageSize)
c.ws.SetReadDeadline(time.Now().Add(pongWait))
c.ws.SetPongHandler(func(string) error {
    c.ws.SetReadDeadline(time.Now().Add(pongWait))
    return nil
})

for {

    //create a new socketMessage
    message := socketMessage{}

    //get the json message from the socket
    err := c.ws.ReadJSON(message)

    if err != nil {
        log.Println(err)
        break
    }
    //add the connection to the message
    message.Connection = c

    shouldBroadcast := message.Process()

    //if the new message should be broadcasted to any user (includeing the
    //one who sent it)
    if shouldBroadcast {
        socketsHub.broadcast <- message
    }
}

}

This is the code we are using on the frontend:

if (window["WebSocket"]) {
  conn = new WebSocket("wss://localhost/api/ws")

  conn.onclose = function(evt) {
    console.log($("<div><b>Connection closed.</b></div>"))
  }
} else {
  console.log($("<div><b>Your browser does not support WebSockets.</b></div>"))
}

Everytime I load any page I get an 'websocket: close 1005' error. I am about to go crazy. Any help would be great.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算
    • ¥15 java如何提取出pdf里的文字?
    • ¥100 求三轴之间相互配合画圆以及直线的算法
    • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
    • ¥15 名为“Product”的列已属于此 DataTable
    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题