Example #1
0
func listener(ctx context.Context, frameSize int, addr string) error {
	ln, err := net.Listen("tcp", addr)
	if err != nil {
		fmt.Fprintf(os.Stderr, "net.Listen(%q): %s\n", addr, err.Error())
		return err
	}
	go func() {
		<-ctx.Done()
		ln.Close()
	}()

	c, err := ln.Accept()
	if err != nil {
		fmt.Fprintf(os.Stderr, "ln.Accept(): %s\n", err.Error())
		return err
	}
	fc := fnet.FromOrderedStream(c, frameSize)
	go func() {
		<-ctx.Done()
		fc.Close()
	}()

	if err = clockstation.Run(ctx, fc, time.Tick(50*time.Millisecond)); err != nil {
		return fmt.Errorf("clockstation.Run: %s\n", err.Error())
	}
	return nil
}
Example #2
0
func dialer(ctx context.Context, frameSize int, addr string) error {

	c, err := net.Dial("tcp", addr)
	if err != nil {
		fmt.Fprintf(os.Stderr, "net.Dial(%q): %s\n", addr, err.Error())
		return err
	}
	fc := fnet.FromOrderedStream(c, frameSize)
	go func() {
		<-ctx.Done()
		fc.Close()
	}()

	if err = clockprinter.Run(ctx, fc); err != nil {
		fmt.Errorf("clockprinter.Run: %s\n", err.Error())
	}
	return nil
}
Example #3
0
func dialer(ctx context.Context, frameSize int, numStreams int, addr string) error {
	rr := fnet.NewRoundRobin(frameSize)
	go func() {
		<-ctx.Done()
		rr.Close()
	}()

	for i := 0; i < numStreams; i++ {

		c, err := net.Dial("tcp", addr)
		if err != nil {
			fmt.Fprintf(os.Stderr, "net.Dial(%q): %s\n", addr, err.Error())
			return err
		}
		fs := fnet.FromOrderedStream(c, frameSize)
		rr.AddConn(fs)
	}
	fc := fnet.FrameConn(rr)

	if err := clockprinter.Run(ctx, fc); err != nil {
		fmt.Errorf("clockprinter.Run: %s\n", err.Error())
	}
	return nil
}