游戏服务器框架php,golang
游戏服务器框架php,golang-Pitaya游戏服务器框架中⽂API教
程
golang -Pitaya 是⼀种简单、快速、轻量级游戏服务器和集群⽀持框架和客户端库iOS、Android,团结和其他⼈通过C SDK。它提供了⼀
个基本的分布式多⼈游戏和服务器端应⽤程序开发框架。
先决条件Go >= 1.10
etcd (⽤于服务发现)
nats (可选的,⽤于发送和接收rpc, grpc实现也可以使⽤,如果喜欢的话)
docker (可选:⽤于在容器上运⾏etcd和nats依赖项)
安装
setup pitaya dependenciesmake setup
Hacking pitaya
下⾯是⼀个跑pitaya的例⼦:
启动etcd(此命令需要docker-compose,并将在本地运⾏etcd容器。etcd可以在没有docker的情况下运⾏。
cd ./examples/testing && docker-compose up -d etcd
run the connector frontend server from cluster_grpc examplemake run-cluster-grpc-example-connector
run the room backend server from the cluster_grpc examplemake run-cluster-grpc-example-room
Now there should be 2 pitaya servers running, a frontend connector and a backend room. To send requests, use a REPL
client for pitaya pitaya-cli.$ pitaya-cli
Pitaya REPL Client>>> connect localhost:3250connected!>>> request room.room.entry>>> sv-> {"code":0,"result":"ok"}
Running the testsmake test
This command will run both unit and e2e tests.
Contributing
#TODO
AuthorsTFG Co - Initial work
License
Acknowledgementsnano authors for building the framework pitaya is based on.
pomelo authors for the inspiration on the distributed design and protocol
Resources
⼀个聊天的demopackage main
import (
"context"
"fmt"
"log"
"net/http"
"strconv"
"time"
"strings"
"/spf13/viper"
"/topfreegames/pitaya"
"/topfreegames/pitaya/acceptor"
"/topfreegames/pitaya/component"
"/topfreegames/pitaya/config"
"/topfreegames/pitaya/groups"
"/topfreegames/pitaya/logger"
"/topfreegames/pitaya/serialize/json"
"/topfreegames/pitaya/timer"
)
type (
// Room represents a component that contains a bundle of room related handler
// like Join/Message
Room struct {
component.Base
timer *timer.Timer
}
// UserMessage represents a message that user sent
UserMessage struct {
Name string `json:"name"`
Content string `json:"content"`
}
// NewUser message will be received when new user