Exemplo n.º 1
0
func server() {

	disp := dispatcher.NewPacketDispatcher()

	dispatcher.RegisterMessage(disp, coredef.TestEchoACK{}, func(ses cellnet.CellID, content interface{}) {
		msg := content.(*coredef.TestEchoACK)

		log.Println("server recv:", msg.String())

		cellnet.Send(ses, &coredef.TestEchoACK{
			Content: proto.String("world"),
		})
	})

	ltvsocket.SpawnAcceptor("127.0.0.1:8001", dispatcher.PeerHandler(disp))
}
Exemplo n.º 2
0
func client() {

	disp := dispatcher.NewPacketDispatcher()

	dispatcher.RegisterMessage(disp, coredef.TestEchoACK{}, func(ses cellnet.CellID, content interface{}) {
		msg := content.(*coredef.TestEchoACK)

		log.Println("client recv:", msg.String())

		done <- true
	})

	dispatcher.RegisterMessage(disp, coredef.ConnectedACK{}, func(ses cellnet.CellID, content interface{}) {
		cellnet.Send(ses, &coredef.TestEchoACK{
			Content: proto.String("hello"),
		})
	})

	ltvsocket.SpawnConnector("127.0.0.1:8001", dispatcher.PeerHandler(disp))

}
Exemplo n.º 3
0
/*
nexus包为cellnet提供了跨进程,机器的访问支持

每个独立操作系统进程就是一个region, 通过配置文件设定region间的互联方法


*/
package nexus

import (
	"github.com/davyxu/cellnet/dispatcher"
)

var Dispatcher = dispatcher.NewPacketDispatcher()

func init() {

	listenNexus()

	joinAddr := config.Join

	if joinAddr != "" {

		joinNexus(joinAddr)
	}
}