Exemplo n.º 1
0
// Creates new http server instance
func New(address string, ctx *message.Context) *server {
	log.Println("Creating HTTP server with address", address)
	server := &server{
		address: address,
		handler: handler.New(ctx),
	}

	return server
}
Exemplo n.º 2
0
// A very basic TCP client, for testing purposes
func main() {
	trn := terrain.New()

	ctx := message.NewClientContext()
	ctx.Terrain = trn
	ctx.Clock = clock.NewService()

	hdlr := handler.New(ctx)

	tlsConfig, err := crypto.GetClientTlsConfig()
	if err != nil {
		log.Println("WARN: could not load TLS config")
	}

	var c net.Conn
	if tlsConfig != nil {
		c, err = tls.Dial("tcp", "127.0.0.1:9999", tlsConfig)
	} else {
		c, err = net.Dial("tcp", "127.0.0.1:9999")
	}

	if err != nil {
		panic("Dial: " + err.Error())
	}

	reader := bufio.NewReader(c)
	clientIO := &message.IO{
		Reader: reader,
		Writer: c,
	}

	go hdlr.Listen(clientIO)

	/*err = builder.SendPing(clientIO.Writer)
	if err != nil {
		panic("SendPing: " + err.Error())
	}*/

	err = builder.SendLogin(clientIO.Writer, "root", "root")
	if err != nil {
		panic("SendLogin: "******"Hello World!")
	if err != nil {
		panic("SendChatSend: " + err.Error())
	}*/

	/*err = c.Close()
	if err != nil {
		panic("Close: " + err.Error())
	}*/
}
Exemplo n.º 3
0
func (e *Engine) listenNewClients() {
	hdlr := handler.New(e.ctx)

	for {
		select {
		case c := <-e.srv.Joins:
			log.Println("Accepting client")
			e.clients[c.Id] = c
			go hdlr.Listen(c.Conn)
		case <-e.listenStop:
			return
		}
	}
}