Esempio n. 1
0
func main() {
	addr := "127.0.0.1:8765"
	server := &osc.Server{}
	conn, err := net.ListenPacket("udp", addr)
	if err != nil {
		fmt.Println("Couldn't listen: ", err)
	}
	defer conn.Close()

	fmt.Println("### Welcome to go-osc receiver demo")
	fmt.Println("Press \"q\" to exit")

	go func() {
		fmt.Println("Start listening on", addr)

		for {
			packet, err := server.ReceivePacket(conn)
			if err != nil {
				fmt.Println("Server error: " + err.Error())
				os.Exit(1)
			}

			if packet != nil {
				switch packet.(type) {
				default:
					fmt.Println("Unknow packet type!")

				case *osc.Message:
					fmt.Printf("-- OSC Message: ")
					osc.PrintMessage(packet.(*osc.Message))

				case *osc.Bundle:
					fmt.Println("-- OSC Bundle:")
					bundle := packet.(*osc.Bundle)
					for i, message := range bundle.Messages {
						fmt.Printf("  -- OSC Message #%d: ", i+1)
						osc.PrintMessage(message)
					}
				}
			}
		}
	}()

	reader := bufio.NewReader(os.Stdin)

	for {
		c, err := reader.ReadByte()
		if err != nil {
			os.Exit(0)
		}

		if c == 'q' {
			os.Exit(0)
		}
	}
}
Esempio n. 2
0
func main() {
	addr := "127.0.0.1:8765"
	server := &osc.Server{Addr: addr}

	server.Handle("/message/address", func(msg *osc.Message) {
		osc.PrintMessage(msg)
	})

	server.ListenAndServe()
}
Esempio n. 3
0
func oscServ(t *ticker) {
	addr := "0.0.0.0:9001"
	server := &osc.Server{Addr: addr}

	server.Handle("/metro", func(msg *osc.Message) {
		osc.PrintMessage(msg)
		if msg.CountArguments() == 1 {
			fmt.Println("message has attr")
			millis := time.Millisecond * time.Duration(msg.Arguments[0].(int32))

			t.Lock()
			t.msgDelay = millis
			t.resetDelay = millis * 8
			t.Unlock()
		}
	})

	go server.ListenAndServe()
}