func newMockDisplay() io.ReadWriteCloser { // Create listener for randomly generated addr addr := slugid.Nice() l, err := mocknet.Listen(addr) if err != nil { // This shouldn't be possible panic(fmt.Sprintf("mocknet.Listen failed using random addr, error: %s", err)) } // Create and start server s := rfb.NewServer(mockDisplayWidth, mockDisplayHeight) go s.Serve(l) // Dial up to server conn, err := mocknet.Dial(addr) if err != nil { // This shouldn't happen either panic(fmt.Sprintf("mocknet.Dial failed, error: %s", err)) } // Handle display when we get a connection from the server go handleDisplay(<-s.Conns) // This works because Conns has a size 16 // Stop listener, we'll create one for each mock display connection l.Close() return conn }
func main() { flag.Parse() ln, err := net.Listen("tcp", *listen) if err != nil { log.Fatal(err) } s := rfb.NewServer(width, height) go func() { err = s.Serve(ln) log.Fatalf("rfb server ended with: %v", err) }() for c := range s.Conns { handleConn(c) } }