Example #1
0
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
}
Example #2
0
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
}
Example #3
0
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)
		}()
	}
}
Example #4
0
func main() {
	session, err := libnet.Connect("tcp", "127.0.0.1:5050", libnet.NewDefCodec(1, 1024, 1024, libnet.BigEndian, TestCodec{}))
	if err != nil {
		panic(err)
	}

	go func() {
		var msg []byte
		for {
			if err := session.Receive(&msg); err != nil {
				break
			}
			fmt.Println("Client receive:", string(msg))
		}
	}()

	for {
		var msg string = "aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffffgggggggggghhhhhhhhhhiiiiiiiiiijjjjjjjjjjkkkkkkkkkkllllllllllmmmmmmmmmmnnnnnnnnnnooooooooooppppppppppqqqqqqqqqqrrrrrrrrrrssssssssssttttttttttuuuuuuuuuuvvvvvvvvvvwwwwwwwwwwssssssssssyyyyyyyyyyzzzzz"

		if err = session.Send([]byte(msg)); err != nil {
			break
		}

		if _, err := fmt.Scanf("%s\n", &msg); err != nil {
			break
		}
	}

	session.Close()
	fmt.Println("client closed!")
}
Example #5
0
func (this *Client) ConnectToMsgServer() (err error) {
	this.keysession, err = libnet.ConnectTimeout(this.cfg.Server_Network, this.cfg.KeyServer_Addr, time.Second*time.Duration(this.cfg.ConnectTimeout), libnet.NewDefCodec(1, 1024, 1024, libnet.BigEndian, this.keycodec))
	if err != nil {
		return err
	}
	this.session, err = libnet.ConnectTimeout(this.cfg.Server_Network, this.cfg.Server_Addr, time.Second*time.Duration(this.cfg.ConnectTimeout),
		libnet.NewDefCodec(2, 1024*1024, 1024, libnet.BigEndian, this.customcodec))
	return err
}
Example #6
0
func (this *MsgServer) ConnectToServer() (err error) {
	this.wsSession, err = libnet.ConnectTimeout(this.cfg.Server_Network, this.cfg.Server_Addr, time.Second*time.Duration(this.cfg.ConnectTimeout), libnet.NewDefCodec(2, 2*1024, 2*1024, libnet.BigEndian, this.customCodec))
	return err
}
Example #7
0
func (this *Client) ConnectToGatewayServer() (err error) {
	this.session, err = libnet.ConnectTimeout(this.cfg.Server_Network, this.cfg.Server_Addr, time.Second*time.Duration(this.cfg.ConnectTimeout),
		libnet.NewDefCodec(1, 1024, 1024, libnet.BigEndian, this.keycodec))
	return err
}
Example #8
0
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
}