Esempio n. 1
0
func (this *TelnetCallback) OnConnect(c *gotcp.Conn) bool {
	addr := c.GetRawConn().RemoteAddr()
	c.PutExtraData(addr)
	fmt.Println("OnConnect:", addr)
	c.AsyncWritePacket(NewTelnetPacket("unknow", []byte("Welcome to this Telnet Server")), 0)
	return true
}
Esempio n. 2
0
func (this *TelnetCallback) OnMessage(c *gotcp.Conn, p gotcp.Packet) bool {
	packet := p.(*TelnetPacket)
	command := packet.GetData()
	commandType := packet.GetType()

	switch commandType {
	case "echo":
		c.AsyncWritePacket(NewTelnetPacket("echo", command), 0)
	case "login":
		c.AsyncWritePacket(NewTelnetPacket("login", []byte(string(command)+" has login")), 0)
	case "quit":
		return false
	default:
		c.AsyncWritePacket(NewTelnetPacket("unknow", []byte("unknow command")), 0)
	}

	return true
}
Esempio n. 3
0
func (this *Callback) OnMessage(c *gotcp.Conn, p gotcp.Packet) bool {
	echoPacket := p.(*protocol.EchoPacket)
	fmt.Printf("OnMessage:[%v] [%v]\n", echoPacket.GetLength(), string(echoPacket.GetBody()))
	c.AsyncWritePacket(protocol.NewEchoPacket(echoPacket.Serialize(), true), time.Second)
	return true
}