Example #1
0
func main() {
	var addr string

	flag.StringVar(&addr, "addr", ":10010", "echo server address")
	flag.Parse()

	server, err := link.Serve("tcp://"+addr, link.Stream(), nil)
	if err != nil {
		panic(err)
	}
	println("server start:", server.Listener().Addr().String())
	server.Loop(link.Echo)
}
Example #2
0
func StartTestGateway(t *testing.T, backendAddr string) *Frontend {
	listener, err := link.ListenPacket("tcp://0.0.0.0:0", link.Packet(link.Uint16BE))
	unitest.NotError(t, err)

	var linkIds []uint64

	gateway := NewFrontend(listener, func(_ *link.Session) (uint64, error) {
		return linkIds[rand.Intn(len(linkIds))], nil
	})

	for i := 0; i < 1; i++ {
		id, err := gateway.AddBackend("tcp://"+backendAddr, link.Stream())
		unitest.NotError(t, err)
		linkIds = append(linkIds, id)
	}

	return gateway
}
Example #3
0
func NewBackend() *Backend {
	return &Backend{link.Stream()}
}