Websockets over WebAssembly generated by golang?

不打扰是莪最后的温柔 提交于 2019-12-06 11:02:45

I have solved it by retrieving the WebSocket object from the global JavaScript object, which in my case is window because I am running this in a browser. I have used only the "syscall/js" library. It looks like this:

ws := js.Global().Get("WebSocket").New("ws://localhost:8080/ws")

ws.Call("addEventListener", "open", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
    fmt.Println("open")

    ws.Call("send", js.TypedArrayOf([]byte{123}))
    return nil
}))

Have a look at the gopherJS websocket library. This one was created to run in the browser (originally js).

I recently saw a youtube video with it being in use in WASM but I couldn't find it any more.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!