cellnet

package module
v0.0.0-...-cccbfae Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2015 License: MIT Imports: 11 Imported by: 0

README

CellNet

A Golang game server framework based on actor model

Feature

本机,跨进程,跨机器通信均使用统一的Actor模型 为游戏服务器优化, 注重开发效率及运行效率

Roadmap

RPC支持 服务器框架例子 服务器可视化部署工具

Dependencies

github.com/golang/protobuf/proto

github.com/BurntSushi/toml

Example

=================================

Hello world



cid := cellnet.Spawn(func(_ cellnet.CellID, cl interface{}) {

	switch v := cl.(type) {
	case string:
		log.Println(v)
	}

})

cellnet.Send(cid, "hello world ")


Client & server with message dispatcher

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))
}

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())

	})

	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))

}

Contact

博客: http://www.cppblog.com/sunicdavy

知乎: http://www.zhihu.com/people/xu-bo-62-87

技术讨论组: 309800774 加群请说明cellnet

邮箱: sunicdavy@qq.com

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// 本进程的ID
	RegionID int32
)

Functions

func GetModuleEntry

func GetModuleEntry(name string) func()

func GetStackInfo

func GetStackInfo(skip int) (string, int)

获取当前调用信息

func GetStackInfoString

func GetStackInfoString(skip int) string

func IsLocal

func IsLocal(id CellID) bool

CellID是否为本进程内的ID

func Name2ID

func Name2ID(name string) int

func ParsePacket

func ParsePacket(pkt *Packet, msgType reflect.Type) (interface{}, error)

func ReadConfig

func ReadConfig(data interface{})

func ReflectContent

func ReflectContent(d interface{}) string

func ReflectProtoName

func ReflectProtoName(msg proto.Message) string

func RegisterModuleEntry

func RegisterModuleEntry(entry func())

func Send

func Send(target CellID, data interface{}) bool

将制定内容发送到target的Cell中

func SendLocal

func SendLocal(target CellID, data interface{}) bool

将制定内容发送到本地的target的Cell中

func SetContentReflector

func SetContentReflector(r ContentReflector)

设置内容解析器

func SetExpressDriver

func SetExpressDriver(driver func(CellID, interface{}) bool)

设置快递驱动, 负责将给定内容跨进程送达

func StartModule

func StartModule()

func StringHashNoCase

func StringHashNoCase(s string) uint32

字符串转为32位整形值

func StripFileName

func StripFileName(filename string, part int) string

将绝对路径按需要的节从右压缩 例如: c:/Develop/nucleus.git/server/src/core/util/stack.go中 当cStripPathSection=3 返回 core/util/stack.go

func Type2ID

func Type2ID(msg proto.Message) int

Types

type CellID

type CellID int64

func NewCellID

func NewCellID(region, index int32) CellID

func Spawn

func Spawn(callback func(CellID, interface{})) CellID

为消息处理函数生成一个Cell, 返回CellID

func (CellID) Index

func (self CellID) Index() int32

func (CellID) Region

func (self CellID) Region() int32

func (CellID) String

func (self CellID) String() string

func (CellID) Valid

func (self CellID) Valid() bool

type ContentReflector

type ContentReflector interface {
	Reflect(interface{}) string
}

func GetContentReflector

func GetContentReflector() ContentReflector

获取内容解析器

type EventDispatcher

type EventDispatcher struct {
	// contains filtered or unexported fields
}

func NewEventDispatcher

func NewEventDispatcher() *EventDispatcher

func (*EventDispatcher) Add

func (self *EventDispatcher) Add(name string, callback func(...interface{}))

func (*EventDispatcher) Clear

func (self *EventDispatcher) Clear()

func (*EventDispatcher) Invoke

func (self *EventDispatcher) Invoke(name string, args ...interface{})

func (*EventDispatcher) Remove

func (self *EventDispatcher) Remove(name string, callback func(...interface{}))

type EventInit

type EventInit struct {
}

type IPacketStream

type IPacketStream interface {
	Read() (*Packet, error)
	Write(pkt *Packet) error
	Close() error
}

封包流

type Packet

type Packet struct {
	MsgID uint32 // 消息ID
	Data  []byte
}

私有协议封包

func BuildPacket

func BuildPacket(msg proto.Message) *Packet

消息到封包

Directories

Path Synopsis
dispatcher包提供以注册+回调方式的消息处理方式, 封装消息解包, 打包的过程
dispatcher包提供以注册+回调方式的消息处理方式, 封装消息解包, 打包的过程
ltvsocket包使用cell框架封装socket层, 同时使用length-type-value格式的私有协议 进行收发封包处理 使用本包可以迅速建立socket互联及统一的开发框架
ltvsocket包使用cell框架封装socket层, 同时使用length-type-value格式的私有协议 进行收发封包处理 使用本包可以迅速建立socket互联及统一的开发框架
nexus包为cellnet提供了跨进程,机器的访问支持 每个独立操作系统进程就是一个region, 通过配置文件设定region间的互联方法
nexus包为cellnet提供了跨进程,机器的访问支持 每个独立操作系统进程就是一个region, 通过配置文件设定region间的互联方法
proto
coredef
Package coredef is a generated protocol buffer package.
Package coredef is a generated protocol buffer package.
sample
tools

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL