I am trying to send an Int8Array from browser to go-socked.io, here is my client's code:
function init(){
conn = io('http://localhost:8080/');
var c = new Int8Array([127]);
conn.emit('m',c)
}
This is my server code
func main() {
server, err := socketio.NewServer(nil)
if err!= nil{
log.Fatal(err)
}
server.On("connection",on_connection)
http.Handle("/socket.io/", server)
http.Handle("/src/", maxAgeHandler(0,http.FileServer(http.Dir("./"))))
http.Handle("/app/", maxAgeHandler(0,http.FileServer(http.Dir("./"))))
http.ListenAndServe(":8080",nil)
}
func on_connection(so socketio.Socket){
log.Println("On connection")
so.Join("Room")
so.On("m",func(msg *socketio.Attachment){
b, _ := ioutil.ReadAll(msg.Data) <---- I got error in this line
fmt.Println(b)
})
}
The error I got said:
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
I would like to know how to read the byte data in the message.