private void Connect_Click(object sender, EventArgs e) { // if there is already an instace dispose of it if (m_Receiver != null) { // dispose of the reciever AppendLine("Disconnecting"); m_Receiver.Dispose(); // wait for the thread to exit (IMPORTANT!) m_Thread.Join(); m_Receiver = null; } // get the ip address from the address box string addressString = m_AddressBox.Text; IPAddress ipAddress; // parse the ip address if (addressString.Trim().Equals("Any", StringComparison.InvariantCultureIgnoreCase) == true) { ipAddress = IPAddress.Any; } else if (IPAddress.TryParse(addressString, out ipAddress) == false) { AppendLine(String.Format("Invalid IP address, {0}", addressString)); return; } // create the reciever instance m_Receiver = new OscReceiver(ipAddress, (int)m_PortBox.Value); // tell the user AppendLine(String.Format("Listening on: {0}:{1}", ipAddress, (int)m_PortBox.Value)); try { // connect to the socket m_Receiver.Connect(); } catch (Exception ex) { this.Invoke(new StringEvent(AppendLine), "Exception while connecting"); this.Invoke(new StringEvent(AppendLine), ex.Message); m_Receiver.Dispose(); m_Receiver = null; return; } // create the listen thread m_Thread = new Thread(ListenLoop); // start listening m_Thread.Start(); }
private void ListenToMessage(IPAddress ipAddress, int port, CancellationToken token) { try { using (_oscReveiver = new OscReceiver(ipAddress, OscServerPort)) { _oscReveiver.Connect(); while (_oscReveiver.State != OscSocketState.Closed && !token.IsCancellationRequested) { // if we are in a state to recieve if (_oscReveiver.State != OscSocketState.Connected) { continue; } // get the next message // this will block until one arrives or the socket is closed var packet = _oscReveiver.Receive(); //Treat the message _taskQueue.Enqueue(() => Task.Run(() => OnMessageReceive(packet))); } } } catch (Exception) { //Exception cause here do nothing for the moment } }
public KinetOSCHandler(int port) { this.port = port; OscConnected = false; ReceiverSemaphore = new Semaphore(1, 1); oscReceiver = new OscReceiver(port); }
public void Run(IInputDevicePluginContext pluginContext) { var port = pluginContext.GetInput <int>("Listening port"); var millisecondThrottle = pluginContext.GetInput <int>("Incoming Midi Throttle (milliseconds)"); using (var listener = new OscReceiver(port)) { var stopWatch = new Stopwatch(); while (listener.State == OscSocketState.Connected) { stopWatch.Stop(); stopWatch.Reset(); stopWatch.Start(); var packet = listener.Receive(); var midiMessage = MidiMessage.FromOscPacket(packet); pluginContext.SetOutput("Midi note", midiMessage.MidiNote.Note); pluginContext.SetOutput("Midi octave", midiMessage.MidiNote.Octave); pluginContext.SetOutput("Midi velocity", midiMessage.Velocity); pluginContext.SignalOutputChange(); while (stopWatch.ElapsedMilliseconds < millisecondThrottle) { listener.Receive(); } } } }
static void Main(string[] args) { m_Listener = new OscAddressManager(); m_Listener.Attach("/testA", TestMethodA); m_Listener.Attach("/testB", TestMethodB); m_Receiver = new OscReceiver(IPAddress.IPv6Any, IPAddress.Parse("FF02::2"), 12345); m_Sender = new OscSender(IPAddress.Parse("FF02::2"), 12345); m_Thread = new Thread(new ThreadStart(ListenLoop)); Console.WriteLine("Connecting"); m_Receiver.Connect(); m_Sender.Connect(); m_Thread.Start(); Console.WriteLine(); Console.WriteLine("Sending message to A"); Console.WriteLine(); m_Sender.Send(new OscMessage("/testA", "Hello from sender (test1)")); Thread.CurrentThread.Join(100); Console.WriteLine(); Console.WriteLine("Press any key to send the next message"); Console.ReadKey(true); Console.WriteLine(); Console.WriteLine("Sending message to B"); Console.WriteLine(); m_Sender.Send(new OscMessage("/testB", "Hello from sender (test2)")); Thread.CurrentThread.Join(100); Console.WriteLine(); Console.WriteLine("Press any key to send the next message"); Console.ReadKey(true); Console.WriteLine(); Console.WriteLine("Sending message to A and B"); Console.WriteLine(); m_Sender.Send(new OscMessage("/*", "Hello from sender (test3)")); Thread.CurrentThread.Join(100); Console.WriteLine(); Console.WriteLine("Press any key to exit"); Console.ReadKey(true); Console.WriteLine("Shutting down"); m_Receiver.Close(); m_Thread.Join(); m_Sender.Close(); }
public Resolume(int listenOnPort, IPAddress sendToAddress, int sendToPort) { _listenerThread = new Thread(new ThreadStart(ListenLoop)); _mutatorThread = new Thread(new ThreadStart(MutatorLoop)); _mutatorThread.Priority = ThreadPriority.AboveNormal; _resolumeOscReceiver = new OscReceiver(listenOnPort); _resolumeOscSender = new OscSender(sendToAddress, 0, sendToPort); }
public OscWrapper(Sys sys) { _sys = sys; InitializeClient(); _server = new OscReceiver(s_oscRecieveEndPoint.Address, s_oscRecieveEndPoint.Port); _server.Connect(); Task.Run(() => ListenLoop()); }
public static void Init() { receiver = new OscReceiver(9993); receiver.Connect(); oscWorker = new BackgroundWorker(); oscWorker.DoWork += OscWorker_DoWork; oscWorker.RunWorkerAsync(); }
private void Example_FormClosing(object sender, FormClosingEventArgs e) { if (m_Receiver != null) { // dispose of the reciever m_Receiver.Dispose(); m_Receiver = null; } }
private void Connect_Click(object sender, EventArgs e) { // if there is already an instace dispose of it if (m_Receiver != null) { // disable the timer m_MessageCheckTimer.Enabled = false; // dispose of the reciever AppendLine("Disconnecting"); m_Receiver.Dispose(); m_Receiver = null; } // get the ip address from the address box string addressString = m_AddressBox.Text; IPAddress ipAddress; // parse the ip address if (addressString.Trim().Equals("Any", StringComparison.InvariantCultureIgnoreCase) == true) { ipAddress = IPAddress.Any; } else if (IPAddress.TryParse(addressString, out ipAddress) == false) { AppendLine(String.Format("Invalid IP address, {0}", addressString)); return; } // create the reciever instance m_Receiver = new OscReceiver(ipAddress, (int)m_PortBox.Value); // tell the user AppendLine(String.Format("Listening on: {0}:{1}", ipAddress, (int)m_PortBox.Value)); try { // connect to the socket m_Receiver.Connect(); } catch (Exception ex) { AppendLine("Exception while connecting"); AppendLine(ex.Message); m_Receiver.Dispose(); m_Receiver = null; return; } // enable the timer m_MessageCheckTimer.Enabled = true; }
static void StartLoop(OscReceiver oscReceiver) { // Variables OscPacket packet = null; HeightData height_Z = new HeightData(); StringBuilder sb = new StringBuilder(); Stopwatch sw = new Stopwatch(); string[] extractData; const string START_LINE = "/position"; bool connectionNotification = true; int count = 0; const int CYCLES = 200; // Attempt to establish an OSC connection try { sw.Start(); do { if (oscReceiver.State == OscSocketState.Connected) { if (connectionNotification) { Console.WriteLine("connection established"); connectionNotification = false; } // Attempt receive OSC packet if (oscReceiver.TryReceive(out packet)) { // Extract position data from OSC packet if (packet.ToString().StartsWith(START_LINE)) { extractData = packet.ToString().Split(','); int zValue = int.Parse(extractData[4]); // Extract 'z' position value (height) Console.WriteLine("{4} - Position:\tx:{0}, y:{1}, z:{2}, \tZ_ERROR:{3} ]", extractData[2], extractData[3], extractData[4], height_Z.GetError(zValue), count); sb.AppendLine(string.Format("{0},{1},{2}", extractData[2], extractData[3], extractData[4])); count++; } } } } while (count < CYCLES); sw.Stop(); Console.WriteLine("TOTAL COUNT: " + count); Console.WriteLine("TOTAL TIME: " + sw.ElapsedMilliseconds / 1000); Console.WriteLine(count / (sw.ElapsedMilliseconds / 1000) + " Hz"); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("Error average: {0}", height_Z.GetErrorAverage()); FILE_IO.WriteLog(sb.ToString()); }
//! Disconnect the state listener public void Disconnect() { if (receiver != null) { receiver.Close(); } receiver = null; connected = false; }
public UDPReceiver(int port, SessionManager sessionManager, KinectProcessor dataPub) { _port = port; _sessionManager = sessionManager; _dataPub = dataPub; _receiver = new OscReceiver(_port); _listenerThread = new Thread(new ThreadStart(ListenerWork)); _receiver.Connect(); _listenerThread.Start(); }
/** * Spawns thread to listen for messages using the port number * denoted by the constructor. * * @see Esc.StateListener.Listen */ public void Connect() { try { receiver = new OscReceiver(port); thread = new Thread(new ThreadStart(Listen)); thread.Start(); connected = true; } catch (Exception e) { Console.WriteLine("failed to connect to port " + port); Console.WriteLine(e.Message); } }
public UdpConnectionImplementation(Connection connection, UdpConnectionInfo info, OscCommunicationStatistics statistics) { this.connection = connection; udpConnectionInfo = info; oscReceiver = new OscReceiver(info.AdapterIPAddress, info.ReceivePort, OscReceiver.DefaultMessageBufferSize, OscReceiver.DefaultPacketSize); oscReceiver.Statistics = statistics; oscSender = new OscSender(info.AdapterIPAddress, 0, info.SendIPAddress, info.SendPort, OscSender.DefaultMulticastTimeToLive, OscSender.DefaultMessageBufferSize, OscSender.DefaultPacketSize); oscSender.Statistics = statistics; }
private void Example_FormClosing(object sender, FormClosingEventArgs e) { if (m_Receiver != null) { // dispose of the reciever m_Receiver.Dispose(); // wait for the thread to exit m_Thread.Join(); m_Receiver = null; } }
private void OpenReceiver(ushort port) { // Update port list if (!receivePorts.Contains(port)) { receivePorts.Add(port); receivePorts.Sort(); } toolStripMenuItemReceivePort.DropDownItems.Clear(); foreach (ushort p in receivePorts) { toolStripMenuItemReceivePort.DropDownItems.Add(p.ToString()); } toolStripMenuItemReceivePort.DropDownItems.Add("..."); // Check selected port foreach (ToolStripMenuItem toolStripMenuItem in toolStripMenuItemReceivePort.DropDownItems) { if (toolStripMenuItem.Text == port.ToString()) { toolStripMenuItem.Checked = true; } } // Open receiver if (oscReceiver != null) { oscReceiver.Close(); } if (thread != null) { thread.Join(); } oscReceiver = new OscReceiver(port); thread = new Thread(new ThreadStart(delegate() { try { while (oscReceiver.State != OscSocketState.Closed) { if (oscReceiver.State == OscSocketState.Connected) { DeconstructPacket(oscReceiver.Receive()); } } } catch { } })); oscReceiver.Connect(); thread.Start(); }
private void Disconnect() { // If the receiver exists if (m_Receiver != null) { // Disconnect the receiver Debug.Log("Disconnecting Receiver"); m_Receiver.Dispose(); // Nullifiy the receiver m_Receiver = null; } }
public MainWindow() { InitializeComponent(); // this.sender = new OscSender(System.Net.IPAddress.Loopback, 0, 5005); // this.sender = new OscSender(System.Net.IPAddress.Parse("192.168.240.123"), 0, 5005); // this.sender = new OscSender(System.Net.IPAddress.Parse("192.168.240.226"), 0, 5005); this.sender = new OscSender(System.Net.IPAddress.Parse("192.168.240.115"), 0, 5005); // this.sender = new OscSender(System.Net.IPAddress.Parse("192.168.1.106"), 0, 5005); this.sender.Connect(); this.receiver = new OscReceiver(8000); this.cancelSource = new System.Threading.CancellationTokenSource(); this.receiverTask = new Task(x => { try { while (!this.cancelSource.IsCancellationRequested) { while (this.receiver.State != Rug.Osc.OscSocketState.Closed) { if (this.receiver.State == Rug.Osc.OscSocketState.Connected) { var packet = this.receiver.Receive(); listBoxLog.Dispatcher.Invoke( System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { listBoxLog.Items.Add(string.Format("Received OSC message: {0}", packet)); } )); } } } } catch (Exception ex) { if (ex.Message == "The receiver socket has been disconnected") { // Ignore return; } } }, this.cancelSource.Token, TaskCreationOptions.LongRunning); this.receiver.Connect(); this.receiverTask.Start(); }
public OscMessageRecieverService(IConfiguration config) { _config = config; _configSection = _config.GetSection("OscServer"); _port = int.TryParse(_configSection.GetSection("Port").Value, out int port) ? port : 1234; try { _receiver = new OscReceiver(_port); _thread = new Thread(ListenLoop); _receiver.Connect(); _thread.Start(); } catch (Exception ex) { _exceptions.Enqueue(ex); } }
private void ConnectFunction(object sender, RoutedEventArgs e) { Console.WriteLine("接続処理"); oscReceiver = new OscReceiver(2345); // Create a thread to do the listening thread = new Thread(new ThreadStart(ListenLoop)); // Connect the receiver oscReceiver.Connect(); // Start the listen thread thread.Start(); }
private void ReconnectListener(int port) { if (_receiver?.State == OscSocketState.Connected) { _receiver.Close(); } _receiveTask?.Wait(); _receiveTask?.Dispose(); _receiver?.Dispose(); _receiver = new OscReceiver(port); _receiver.Connect(); _receiveTask = Task.Run(async() => await ListenLoop()); }
public MainWindow() { InitializeComponent(); // this.sender = new OscSender(System.Net.IPAddress.Loopback, 0, 5005); // this.sender = new OscSender(System.Net.IPAddress.Parse("192.168.240.123"), 0, 5005); // this.sender = new OscSender(System.Net.IPAddress.Parse("192.168.240.226"), 0, 5005); this.sender = new OscSender(System.Net.IPAddress.Parse("192.168.240.115"), 0, 5005); // this.sender = new OscSender(System.Net.IPAddress.Parse("192.168.1.106"), 0, 5005); this.sender.Connect(); this.receiver = new OscReceiver(8000); this.cancelSource = new System.Threading.CancellationTokenSource(); this.receiverTask = new Task(x => { try { while (!this.cancelSource.IsCancellationRequested) { while (this.receiver.State != Rug.Osc.OscSocketState.Closed) { if (this.receiver.State == Rug.Osc.OscSocketState.Connected) { var packet = this.receiver.Receive(); listBoxLog.Dispatcher.Invoke( System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { listBoxLog.Items.Add(string.Format("Received OSC message: {0}", packet)); } )); } } } } catch (Exception ex) { if (ex.Message == "The receiver socket has been disconnected") // Ignore return; } }, this.cancelSource.Token, TaskCreationOptions.LongRunning); this.receiver.Connect(); this.receiverTask.Start(); }
//受信待受開始 public OSC(int port, Action <OscBundle> OnBundle, Action <OscMessage> OnMessage) { this.Port = port; this.OnBundle = OnBundle; this.OnMessage = OnMessage; //受信待受 oscReceiver = new OscReceiver(this.Port); oscReceiver.Connect(); //受信処理スレッド thread = new Thread(new ThreadStart(ReceiveThread)); thread.Start(); //例外は上位に打ち上げる }
public OscWrapper(IPEndPoint receiveEndpoint, ILogger logger) { _logger = logger; bool isMulticast = IsMulticast(receiveEndpoint.Address); if (isMulticast) { _server = new OscReceiver(IPAddress.Any, receiveEndpoint.Address, receiveEndpoint.Port, MaxPacketSize, MessageBufferSize); } else { _server = new OscReceiver(receiveEndpoint.Address, receiveEndpoint.Port, MaxPacketSize, MessageBufferSize); } _server.Connect(); _logger.LogInformation("Listening for OSC commands on {0} address {1} with message buffer size of {2}kB", isMulticast ? "multicast" : "unicast", receiveEndpoint, MessageBufferSize / 1024); Task.Run(() => ListenLoop()); }
static void Main(string[] args) { IPAddress IPaddress = IPAddress.Parse("127.0.0.1"); int port = 8888; OscReceiver oscReceiver = new OscReceiver(IPaddress, port); oscReceiver.Connect(); Console.Write("Waiting for OSC connection...\n\n"); StartLoop(oscReceiver); oscReceiver.Close(); Console.WriteLine("OSC Connection closed."); Console.ReadKey(); }
// Constructor for the main dashboard window. public MainWindow() { // Initializes components in the XAML. InitializeComponent(); // Set the data to the data grid. OscDataGrid.ItemsSource = ReceivedOscData; // Create the OSC receiver. Receiver = new OscReceiver(ReceivePortNumber); // Create a thread to do the listening. OscThread = new Thread(new ThreadStart(ListenLoop)); // Connect the receiver. Receiver.Connect(); // Start the listening thread. OscThread.Start(); }
protected override void OnStart(string[] args) { MidiIn = CreateMidiIn(Settings.Default.InputMidiDevice); OscOut = new OscSender(IPAddress.Parse(Settings.Default.OscHost), 0, Settings.Default.OscPortOut); OscOut.Connect(); OscIn = new OscReceiver(IPAddress.Parse(Settings.Default.OscHost), Settings.Default.OscPortIn); Task.Run(() => { OscIn.Connect(); var running = true; while (running) { try { var packet = OscIn.Receive(); var messages = ExplodeBundle(packet); foreach (var message in messages) { try { var msg = new OscEventArgs(message.Address, message.ToArray()); WriteDebug($"Got OSC: {msg}"); OscMessageReceived?.Invoke(this, msg); } catch { // ignore } } } catch { running = false; } } }); LoadPlugins(); }
//受信待受開始 public InputOSC(string name, int port, Action <string, OscBundle> OnBundle, Action <string, OscMessage> OnMessage) { if (name == null) { throw new ArgumentNullException(); } this.Name = name; this.Port = port; this.OnBundle = OnBundle; this.OnMessage = OnMessage; //受信待受 oscReceiver = new OscReceiver(this.Port); oscReceiver.Connect(); //受信処理スレッド thread = new Thread(new ThreadStart(ReceiveThread)); thread.Start(); //例外は上位に打ち上げる }
//受信待受開始 public OSC(string adr, int portRx, int portTx, Action <OscBundle> OnBundle, Action <OscMessage> OnMessage) { this.Port = portRx; this.OnBundle = OnBundle; this.OnMessage = OnMessage; //送信 IPAddress ip = IPAddress.Parse(adr); oscSender = new OscSender(ip, 0, portTx); oscSender.Connect(); //受信待受 oscReceiver = new OscReceiver(portRx); oscReceiver.Connect(); //受信処理スレッド thread = new Thread(new ThreadStart(ReceiveThread)); thread.Start(); //例外は上位に打ち上げる }
private void OpenReceiver(ushort port) { // Update port list if (!receivePorts.Contains(port)) { receivePorts.Add(port); receivePorts.Sort(); } toolStripMenuItemReceivePort.DropDownItems.Clear(); foreach (ushort p in receivePorts) { toolStripMenuItemReceivePort.DropDownItems.Add(p.ToString()); } toolStripMenuItemReceivePort.DropDownItems.Add("..."); // Check selected port foreach (ToolStripMenuItem toolStripMenuItem in toolStripMenuItemReceivePort.DropDownItems) { if (toolStripMenuItem.Text == port.ToString()) { toolStripMenuItem.Checked = true; } } // Open reciever if (m_Receiver != null) { m_Receiver.Close(); } if (m_Thread != null) { m_Thread.Join(); } m_Listener = new OscListenerManager(); m_Receiver = new OscReceiver(port); m_Thread = new Thread(new ThreadStart(ListenLoop)); m_Receiver.Connect(); m_Thread.Start(); }
void Awake() { // Log the start Debug.Log("Starting Osc Receiver"); // Ensure that the receiver is disconnected Disconnect(); // The address to listen on to IPAddress address = IPAddress.Any; // The port to listen on int port = ListenPort; // Create an instance of the receiver m_Receiver = new OscReceiver(address, port); // Connect the receiver m_Receiver.Connect(); // We are now connected Debug.Log("Connected Receiver"); }
void Start() { reciever = new OscReceiver(port); reciever.Connect(); listener = new OscAddressManager(); foreach(OscRecieveData data in recieveDatas) { data.value = OscNull.Value; data.valueString = data.value.ToString(); listener.Attach(data.address, OnRecieved); } thread = new Thread(new ThreadStart(ListenLoop)); thread.Start(); }