-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
43 lines (35 loc) · 1.1 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"github.com/team4yf/yf-fpm-server-go/fpm"
_ "github.com/team4yf/fpm-go-plugin-tcp/plugin"
)
func main() {
app := fpm.New()
app.Init()
// app.Execute("mqttclient.subscribe", &fpm.BizParam{
// "topics": "$s2d/+/ipc/demo/execute",
// })
app.Subscribe("#tcp/receive", func(topic string, data interface{}) {
//data 通常是 byte[] 类型,可以转成 string 或者 map
payload := data.(map[string]interface{})
app.Logger.Debugf("receive tcp hex data: %x", payload["data"])
clientID := payload["clientID"].(string)
app.Execute("socket.setID", &fpm.BizParam{
"clientID": clientID,
"id": "abc",
})
app.Execute("socket.send", &fpm.BizParam{
"clientID": "abc",
"data": []byte{97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97},
})
})
app.Subscribe("#tcp/disconnect", func(_ string, data interface{}) {
// data: { "id": "abc", "clientID": "bcd" }
app.Logger.Debugf("data: %+v", data)
})
// app.Execute("mqttclient.publish", &fpm.BizParam{
// "topic": "$s2d/111/ipc/demo/feedback",
// "payload": ([]byte)(`{"test":1}`),
// })
app.Run()
}