예제 #1
0
파일: main.go 프로젝트: huangbenyu/cellnet
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))
}
예제 #2
0
파일: main.go 프로젝트: huangbenyu/cellnet
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))

}
예제 #3
0
파일: nexus.go 프로젝트: huangbenyu/cellnet
/*
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)
	}
}