Ejemplo n.º 1
0
func (s *ServerDelegateImpl) ConnectionDidReceiveData(connection *network.Connection, length int, data []byte) {

	fmt.Printf("Received len: %v data: %v", length, string(data))

	// we want to trim off the whitespace, including the inevitable cr
	command := strings.Trim(string(data), "\r\n ")

	if command == "quit" {
		connection.SendString("Goodbye!\n")
		connection.Close()
		return
	} else if command == "who" {
		connection.SendString(fmt.Sprintf("%v users online\n", len(connection.Server.Connections)))
	} else if command == "stop server" {
		connection.Close()
		connection.Server.Stop()
		return
	}

	connection.SendString("THX\n")
	connection.SendString("OK ")
}
Ejemplo n.º 2
0
func (s *ServerDelegateImpl) ConnectionDidConnect(connection *network.Connection) {
	fmt.Println("Connection was made!")
	connection.SendString("OK ")
}