I want to send data from Android to Golang with socket.io . I do that with Nodejs correctly But now , i want do with Go. I cant find simple example.how can i do that?
1条回答 默认 最新
- duanruinong0619 2019-01-02 04:53关注
I assume you would like to use a Go implementation of a Socket.IO server library instead of the standard Node.js one. If so, you can try googollee/go-socket.io project. Here is an example from the project page:
package main import ( "log" "net/http" "github.com/googollee/go-socket.io" ) func main() { server, err := socketio.NewServer(nil) if err != nil { log.Fatal(err) } server.On("connection", func(so socketio.Socket) { log.Println("on connection") so.Join("chat") so.On("chat message", func(msg string) { log.Println("emit:", so.Emit("chat message", msg)) server.BroadcastTo("chat", "chat message", msg) }) so.On("disconnection", func() { log.Println("on disconnect") }) }) server.On("error", func(so socketio.Socket, err error) { log.Println("error:", err) }) http.Handle("/socket.io/", server) http.Handle("/", http.FileServer(http.Dir("./asset"))) log.Println("Serving at localhost:5000...") log.Fatal(http.ListenAndServe(":5000", nil)) }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 暴力法无法解出,可能要使用dp和数学知识
- ¥15 wpf通过绑定控件自身的值,来实现背景颜色的切换
- ¥15 CDH6.3 运行hive -e hive -e "show databases;"报错:hive-env.sh:行24: hbase-common.jar: 权限不够
- ¥15 SSRS制作的报表打开报错,无法正常显示网页
- ¥15 乌班图ip地址配置及远程SSH
- ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
- ¥15 PSPICE制作一个加法器
- ¥15 javaweb项目无法正常跳转
- ¥15 VMBox虚拟机无法访问
- ¥15 skd显示找不到头文件