代码拉取完成,页面将自动刷新
package main
import (
"flag"
"fmt"
"strings"
"gitee.com/mixerj/pitaya"
"gitee.com/mixerj/pitaya/acceptor"
"gitee.com/mixerj/pitaya/component"
"gitee.com/mixerj/pitaya/examples/demo/cluster_protobuf/services"
"gitee.com/mixerj/pitaya/serialize/protobuf"
)
func configureBackend() {
room := services.NewRoom()
pitaya.Register(room,
component.WithName("room"),
component.WithNameFunc(strings.ToLower),
)
pitaya.RegisterRemote(room,
component.WithName("room"),
component.WithNameFunc(strings.ToLower),
)
}
func configureFrontend(port int) {
ws := acceptor.NewWSAcceptor(fmt.Sprintf(":%d", port))
pitaya.Register(&services.Connector{},
component.WithName("connector"),
component.WithNameFunc(strings.ToLower),
)
pitaya.RegisterRemote(&services.ConnectorRemote{},
component.WithName("connectorremote"),
component.WithNameFunc(strings.ToLower),
)
pitaya.AddAcceptor(ws)
}
func main() {
port := flag.Int("port", 3250, "the port to listen")
svType := flag.String("type", "connector", "the server type")
isFrontend := flag.Bool("frontend", true, "if server is frontend")
flag.Parse()
defer pitaya.Shutdown()
ser := protobuf.NewSerializer()
pitaya.SetSerializer(ser)
if !*isFrontend {
configureBackend()
} else {
configureFrontend(*port)
}
pitaya.Configure(*isFrontend, *svType, pitaya.Cluster, map[string]string{})
pitaya.Start()
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。