func (this *MsgServer) NewServer() (err error) { this.keyserver, err = libnet.Serve(this.cfg.Key_Network, this.cfg.Key_Addr, libnet.NewDefCodec(1, 1024, 1024, libnet.BigEndian, this.keyCodec)) if err != nil { return err } this.server, err = libnet.Serve(this.cfg.Network, this.cfg.Addr, libnet.NewDefCodec(2, 1024*1024, 1024, libnet.BigEndian, this.customCodec)) return err }
func (this *WorldServer) NewServer() (err error) { this.keyserver, err = libnet.Serve(this.cfg.Key_Network, this.cfg.Key_Addr, libnet.NewDefCodec(1, 1024, 1024, libnet.BigEndian, this.keyCodec)) if err != nil { return err } this.server, err = libnet.Serve(this.cfg.Network, this.cfg.Addr, libnet.NewDefCodec(2, 2*1024, 2*1024, libnet.BigEndian, this.customCodec)) if err != nil { return err } //设定 RC4 密钥 this.customCodec.SetKey(this.cfg.Rc4Key) //连接数据库 err = this.database.Open() return err }
func main() { var addr string = "127.0.0.1:5050" server, err := libnet.Serve("tcp", addr, libnet.NewDefCodec(1, 1024, 1024, libnet.BigEndian, TestCodec{})) if err != nil { panic(err) } println("Echo Server start:", server.GetListener().Addr().String()) for { session, err := server.Accept() if err != nil { break } go func() { clientaddr := session.GetConn().RemoteAddr().String() println("Client conn:", clientaddr) for { var msg []byte if err = session.Receive(&msg); err != nil { break } println("receive msg:", string(msg)) if err = session.Send(msg); err != nil { break } } println("Client Closed:", clientaddr) }() } }
func (this *Gateway) NewServer() (err error) { this.server, err = libnet.Serve(this.cfg.Network, this.cfg.Addr, libnet.NewDefCodec(1, 1024, 1024, libnet.BigEndian, this.keycodec)) return err }