googollee / go-socket.io

socket.io library for golang, a realtime application framework.
Other
5.63k stars 826 forks source link

how to receive binary message? #601

Open amos-lsl opened 11 months ago

amos-lsl commented 11 months ago

how to receive binary message?

calfzhou commented 10 months ago

Simple add a []byte parameter to the event handler should be enough.

    type barType struct {
        Text string `json:"text"`
        Data []byte `json:"data"`
    }
    server.OnEvent("/", "bar", func(s socketio.Conn, payload *barType) string {
        text := payload.Text
        data := payload.Data
        fmt.Println(text, data)
        return fmt.Sprintf("Ack of bar %s %s", text, data)
    })
image