本文整理汇总了Golang中github.com/davyxu/cellnet.NewEventPipe函数的典型用法代码示例。如果您正苦于以下问题:Golang NewEventPipe函数的具体用法?Golang NewEventPipe怎么用?Golang NewEventPipe使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewEventPipe函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: client
func client() {
pipe := cellnet.NewEventPipe()
p := socket.NewConnector(pipe).Start("127.0.0.1:7201")
rpc.InstallClient(p)
socket.RegisterSessionMessage(p, coredef.SessionConnected{}, func(content interface{}, ses cellnet.Session) {
rpc.Call(p, &coredef.TestEchoACK{
Content: "rpc hello",
}, func(msg *coredef.TestEchoACK) {
log.Debugln("client recv", msg.Content)
signal.Done(1)
})
})
pipe.Start()
signal.WaitAndExpect(1, "not recv data")
}
开发者ID:faquiiR,项目名称:cellnet,代码行数:25,代码来源:rpc_test.go
示例2: server
func server() {
pipe := cellnet.NewEventPipe()
qpsm := benchmark.NewQPSMeter(pipe, func(qps int) {
log.Infof("QPS: %d", qps)
})
evq := socket.NewAcceptor(pipe).Start(benchmarkAddress)
socket.RegisterSessionMessage(evq, "gamedef.TestEchoACK", func(content interface{}, ses cellnet.Session) {
if qpsm.Acc() > benchmarkSeconds {
signal.Done(1)
log.Infof("Average QPS: %d", qpsm.Average())
}
ses.Send(&gamedef.TestEchoACK{})
})
pipe.Start()
}
开发者ID:davyxu,项目名称:cellnet,代码行数:26,代码来源:io_test.go
示例3: client
// 客户端
func client() {
pipe := cellnet.NewEventPipe()
evq := socket.NewConnector(pipe).Start("127.0.0.1:7101")
socket.RegisterSessionMessage(evq, "coredef.SessionConnected", func(content interface{}, ses cellnet.Session) {
signal.Done(1)
ack := &coredef.TestEchoACK{
Content: "hello",
}
ses.Send(ack)
log.Debugf("client send: %s\n", ack.String())
})
socket.RegisterSessionMessage(evq, "coredef.TestEchoACK", func(content interface{}, ses cellnet.Session) {
msg := content.(*coredef.TestEchoACK)
log.Debugln("client recv:", msg.String())
signal.Done(3)
})
pipe.Start()
signal.WaitAndExpect(1, "not connceted to router")
signal.WaitAndExpect(2, "not recv client msg")
signal.WaitAndExpect(3, "not recv server msg")
}
开发者ID:CaiGuaiNi,项目名称:cellnet,代码行数:35,代码来源:router_test.go
示例4: runServer
func runServer() {
pipe := cellnet.NewEventPipe()
p := socket.NewAcceptor(pipe).Start("127.0.0.1:7235")
// 计数器, 应该按照connCount倍数递增
var counter int
socket.RegisterSessionMessage(p, coredef.TestEchoACK{}, func(ses cellnet.Session, content interface{}) {
msg := content.(*coredef.TestEchoACK)
counter++
log.Printf("No. %d: server recv: %v", counter, msg.String())
// 发包后关闭
ses.Send(&coredef.TestEchoACK{
Content: proto.String(msg.GetContent()),
})
if msg.GetContent() != "noclose" {
ses.Close()
}
})
pipe.Start()
done <- 0
}
开发者ID:zhutaorun,项目名称:cellnet,代码行数:30,代码来源:main.go
示例5: TestTimer
func TestTimer(t *testing.T) {
signal := test.NewSignalTester(t)
pipe := cellnet.NewEventPipe()
evq := pipe.AddQueue()
pipe.Start()
const testTimes = 3
var count int = testTimes
cellnet.NewTimer(evq, time.Second, func(t *cellnet.Timer) {
log.Debugln("timer 1 sec tick")
signal.Done(1)
count--
if count == 0 {
t.Stop()
signal.Done(2)
}
})
for i := 0; i < testTimes; i++ {
signal.WaitAndExpect(1, "timer not tick")
}
signal.WaitAndExpect(2, "timer not stop")
}
开发者ID:CaiGuaiNi,项目名称:cellnet,代码行数:34,代码来源:timer_test.go
示例6: client
func client() {
pipe := cellnet.NewEventPipe()
evq := socket.NewConnector(pipe).Start("127.0.0.1:7201")
socket.RegisterSessionMessage(evq, "gamedef.TestEchoACK", func(content interface{}, ses cellnet.Session) {
msg := content.(*gamedef.TestEchoACK)
log.Debugln("client recv:", msg.String())
signal.Done(1)
})
socket.RegisterSessionMessage(evq, "gamedef.SessionConnected", func(content interface{}, ses cellnet.Session) {
ses.Send(&gamedef.TestEchoACK{
Content: "hello",
})
})
pipe.Start()
signal.WaitAndExpect(1, "not recv data")
}
开发者ID:davyxu,项目名称:cellnet,代码行数:27,代码来源:echo_test.go
示例7: client
func client() {
pipe := cellnet.NewEventPipe()
p := socket.NewConnector(pipe)
p.SetName("client")
p.Start("127.0.0.1:9201")
socket.RegisterSessionMessage(p, "gamedef.SessionConnected", func(content interface{}, ses cellnet.Session) {
rpc.Call(p, &gamedef.TestEchoACK{
Content: "rpc async call",
}, func(msg *gamedef.TestEchoACK) {
log.Debugln("client recv", msg.Content)
signal.Done(1)
})
})
pipe.Start()
signal.WaitAndExpect(1, "not recv data")
}
开发者ID:davyxu,项目名称:cellnet,代码行数:25,代码来源:rpc_test.go
示例8: backendServer
// 后台服务器
func backendServer() {
gate.DebugMode = true
pipe := cellnet.NewEventPipe()
gate.StartGateConnector(pipe, []string{"127.0.0.1:7201"})
gate.RegisterSessionMessage(coredef.SessionClosed{}, func(content interface{}, gateSes cellnet.Session, clientid int64) {
log.Printf("client closed gate: %d clientid: %d\n", gateSes.ID(), clientid)
})
gate.RegisterSessionMessage(coredef.TestEchoACK{}, func(content interface{}, gateSes cellnet.Session, clientid int64) {
msg := content.(*coredef.TestEchoACK)
log.Printf("recv relay, gate: %d clientid: %d\n", gateSes.ID(), clientid)
gate.SendToClient(gateSes, clientid, &coredef.TestEchoACK{
Content: proto.String(msg.GetContent()),
})
})
pipe.Start()
<-done
}
开发者ID:zhutaorun,项目名称:cellnet,代码行数:27,代码来源:main.go
示例9: client
// 客户端
func client() {
pipe := cellnet.NewEventPipe()
evq := socket.NewConnector(pipe).Start("127.0.0.1:7101")
socket.RegisterSessionMessage(evq, coredef.SessionConnected{}, func(content interface{}, ses cellnet.Session) {
ack := &coredef.TestEchoACK{
Content: proto.String("hello"),
}
ses.Send(ack)
log.Printf("client send: %s\n", ack.String())
})
socket.RegisterSessionMessage(evq, coredef.TestEchoACK{}, func(content interface{}, ses cellnet.Session) {
msg := content.(*coredef.TestEchoACK)
log.Println("client recv:", msg.String())
done <- true
})
pipe.Start()
<-done
}
开发者ID:zhutaorun,项目名称:cellnet,代码行数:30,代码来源:main.go
示例10: routerServer
// 网关服务器
func routerServer() {
router.DebugMode = true
pipe := cellnet.NewEventPipe()
router.StartBackendAcceptor(pipe, "127.0.0.1:7201", "svc->backend")
router.StartFrontendAcceptor(pipe, "127.0.0.1:7101", "client->router")
pipe.Start()
}
开发者ID:CaiGuaiNi,项目名称:cellnet,代码行数:13,代码来源:router_test.go
示例11: gateServer
// 网关服务器
func gateServer() {
gate.DebugMode = true
pipe := cellnet.NewEventPipe()
gate.StartBackendAcceptor(pipe, "127.0.0.1:7201")
gate.StartClientAcceptor(pipe, "127.0.0.1:7101")
pipe.Start()
}
开发者ID:faquiiR,项目名称:cellnet,代码行数:13,代码来源:gate_test.go
示例12: connClose
// 客户端连接上后, 主动断开连接, 确保连接正常关闭
func connClose() {
pipe := cellnet.NewEventPipe()
p := socket.NewConnector(pipe).Start("127.0.0.1:7235")
socket.RegisterSessionMessage(p, coredef.SessionConnected{}, func(ses cellnet.Session, content interface{}) {
// 连接上发包,告诉服务器不要断开
ses.Send(&coredef.TestEchoACK{
Content: proto.String("noclose"),
})
})
socket.RegisterSessionMessage(p, coredef.TestEchoACK{}, func(ses cellnet.Session, content interface{}) {
msg := content.(*coredef.TestEchoACK)
log.Println("client recv:", msg.String())
done <- 1
// 客户端主动断开
ses.Close()
})
socket.RegisterSessionMessage(p, coredef.SessionClosed{}, func(ses cellnet.Session, content interface{}) {
log.Println("close ok!")
// 正常断开
done <- 2
})
pipe.Start()
// 收到回包
if <-done != 1 {
log.Panicln("test failed, not recv msg")
}
// 断开正常
if <-done != 2 {
log.Panicln("test failed, not close")
}
fmt.Println("connected close test done!")
}
开发者ID:zhutaorun,项目名称:cellnet,代码行数:50,代码来源:main.go
示例13: multiConn
// 多连接收封包后被服务器关闭, 确保收到封包
func multiConn() {
pipe := cellnet.NewEventPipe()
// 同步量
var endAcc sync.WaitGroup
// 启动N个连接
for i := 0; i < connCount; i++ {
endAcc.Add(1)
p := socket.NewConnector(pipe).Start("127.0.0.1:7235")
p.SetName(fmt.Sprintf("%d", i))
socket.RegisterSessionMessage(p, coredef.TestEchoACK{}, func(ses cellnet.Session, content interface{}) {
msg := content.(*coredef.TestEchoACK)
log.Println("client recv:", msg.String())
// 正常收到
endAcc.Done()
})
socket.RegisterSessionMessage(p, coredef.SessionConnected{}, func(ses cellnet.Session, content interface{}) {
id, _ := strconv.Atoi(ses.FromPeer().Name())
// 连接上发包
ses.Send(&coredef.TestEchoACK{
Content: proto.String(fmt.Sprintf("data#%d", id)),
})
})
}
pipe.Start()
// 等待完成
endAcc.Wait()
fmt.Println("multi connection close test done!")
}
开发者ID:zhutaorun,项目名称:cellnet,代码行数:47,代码来源:main.go
示例14: gateServer
// 网关服务器
func gateServer() {
gate.DebugMode = true
pipe := cellnet.NewEventPipe()
gate.StartBackendAcceptor(pipe, "127.0.0.1:7201")
gate.StartClientAcceptor(pipe, "127.0.0.1:7101")
socket.RegisterSessionMessage(gate.ClientAcceptor, coredef.SessionAccepted{}, func(content interface{}, ses cellnet.Session) {
log.Println("client accepted", ses.ID())
})
pipe.Start()
<-done
}
开发者ID:zhutaorun,项目名称:cellnet,代码行数:20,代码来源:main.go
示例15: server
func server() {
pipe := cellnet.NewEventPipe()
evq := socket.NewAcceptor(pipe).Start("127.0.0.1:7234")
socket.RegisterSessionMessage(evq, coredef.TestEchoACK{}, func(content interface{}, ses cellnet.Session) {
msg := content.(*coredef.TestEchoACK)
log.Println("server recv:", msg.String())
ses.Send(&coredef.TestEchoACK{
Content: proto.String(msg.String()),
})
})
pipe.Start()
}
开发者ID:zhutaorun,项目名称:cellnet,代码行数:20,代码来源:main.go
示例16: TestDelay
func TestDelay(t *testing.T) {
signal := test.NewSignalTester(t)
pipe := cellnet.NewEventPipe()
evq := pipe.AddQueue()
pipe.Start()
log.Debugln("delay 1 sec begin")
evq.DelayPostData(time.Second, func() {
log.Debugln("delay done")
signal.Done(1)
})
signal.WaitAndExpect(1, "delay not work")
}
开发者ID:CaiGuaiNi,项目名称:cellnet,代码行数:20,代码来源:timer_test.go
示例17: server
func server() {
pipe := cellnet.NewEventPipe()
evq := socket.NewAcceptor(pipe).Start("127.0.0.1:7201")
socket.RegisterSessionMessage(evq, "gamedef.TestEchoACK", func(content interface{}, ses cellnet.Session) {
msg := content.(*gamedef.TestEchoACK)
log.Debugln("server recv:", msg.String())
ses.Send(&gamedef.TestEchoACK{
Content: msg.String(),
})
})
pipe.Start()
}
开发者ID:davyxu,项目名称:cellnet,代码行数:20,代码来源:echo_test.go
示例18: testConnActiveClose
// 客户端连接上后, 主动断开连接, 确保连接正常关闭
func testConnActiveClose() {
pipe := cellnet.NewEventPipe()
p := socket.NewConnector(pipe).Start("127.0.0.1:7201")
socket.RegisterSessionMessage(p, coredef.SessionConnected{}, func(content interface{}, ses cellnet.Session) {
signal.Done(1)
// 连接上发包,告诉服务器不要断开
ses.Send(&coredef.TestEchoACK{
Content: proto.String("noclose"),
})
})
socket.RegisterSessionMessage(p, coredef.TestEchoACK{}, func(content interface{}, ses cellnet.Session) {
msg := content.(*coredef.TestEchoACK)
log.Debugln("client recv:", msg.String())
signal.Done(2)
// 客户端主动断开
ses.Close()
})
socket.RegisterSessionMessage(p, coredef.SessionClosed{}, func(content interface{}, ses cellnet.Session) {
log.Debugln("close ok!")
// 正常断开
signal.Done(3)
})
pipe.Start()
signal.WaitAndExpect(1, "TestConnActiveClose not connected")
signal.WaitAndExpect(2, "TestConnActiveClose not recv msg")
signal.WaitAndExpect(3, "TestConnActiveClose not close")
}
开发者ID:FengJiaQi,项目名称:cellnet,代码行数:42,代码来源:sendclose_test.go
示例19: server
func server() {
pipe := cellnet.NewEventPipe()
p := socket.NewAcceptor(pipe).Start("127.0.0.1:7201")
rpc.InstallServer(p)
rpc.RegisterMessage(p, coredef.TestEchoACK{}, func(resp rpc.Response, content interface{}) {
msg := content.(*coredef.TestEchoACK)
log.Debugln("server recv:", msg.String())
resp.Feedback(&coredef.TestEchoACK{
Content: msg.String(),
})
})
pipe.Start()
}
开发者ID:faquiiR,项目名称:cellnet,代码行数:21,代码来源:rpc_test.go
示例20: client
func client() {
pipe := cellnet.NewEventPipe()
evq := socket.NewConnector(pipe).Start(benchmarkAddress)
socket.RegisterSessionMessage(evq, "gamedef.TestEchoACK", func(content interface{}, ses cellnet.Session) {
ses.Send(&gamedef.TestEchoACK{})
})
socket.RegisterSessionMessage(evq, "gamedef.SessionConnected", func(content interface{}, ses cellnet.Session) {
ses.Send(&gamedef.TestEchoACK{})
})
pipe.Start()
}
开发者ID:davyxu,项目名称:cellnet,代码行数:21,代码来源:io_test.go
注:本文中的github.com/davyxu/cellnet.NewEventPipe函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论