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(); }
public void StartReceiving() { receivingThread = new Thread(new ThreadStart(ReceiverMethod)); oscReceiver.Connect(); OscConnected = true; receivingThread.Start(); }
public void Start() { _listenerThread.Start(); _resolumeOscReceiver.Connect(); _resolumeOscSender.Connect(); _mutatorThread.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 } }
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 virtual void Connect() { if (!_isDisposed) { _sender.Connect(); _reciever.Connect(); } }
public static void Init() { receiver = new OscReceiver(9993); receiver.Connect(); oscWorker = new BackgroundWorker(); oscWorker.DoWork += OscWorker_DoWork; oscWorker.RunWorkerAsync(); }
public OscWrapper(Sys sys) { _sys = sys; InitializeClient(); _server = new OscReceiver(s_oscRecieveEndPoint.Address, s_oscRecieveEndPoint.Port); _server.Connect(); Task.Run(() => ListenLoop()); }
public void Connect() { OscReceiver.Connect(); thread = new Thread(this.ListenLoop) { Name = "Osc Package Listener " + OscReceiver }; thread.Start(); }
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; }
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(); }
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 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 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); } }
public override void Connect() { oscReceiver.Connect(); oscSender.Connect(); thread = new Thread(new ThreadStart(ReceiveLoop)); thread.Name = "Udp Connection Implementation Receive Loop" + udpConnectionInfo.ToString(); if (oscReceiver.State != OscSocketState.Connected && oscSender.State != OscSocketState.Connected) { throw new Exception(string.Format(Strings.UdpConnectionImplementation_FailedToConnect, udpConnectionInfo.ToString())); } connection.OnInfo(string.Format(Strings.UdpConnectionImplementation_Connected, udpConnectionInfo.ToString())); }
//受信待受開始 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()); }
/// <summary> /// Receives the next available OSC packet relative to the Pozyx TagID, /// splits the csv data values, and stores into a string array /// </summary> public static string[] GetOSCPacket(string tagID) { OscPacket packet; string[] extractData = null; const string START_LINE = "/position"; bool gotCorrectPacket = false; // Attempt to establish an OSC connection and receive packet try { // Connect to OSC _OSCReceiver.Connect(); do { if (_OSCReceiver.State == OscSocketState.Connected) { // Attempt to receive OSC packet packet = _OSCReceiver.Receive(); // Extract data from OSC packet if (packet.ToString().StartsWith(START_LINE)) { extractData = packet.ToString().Split(','); // Multi-Tag Functionality // Checks packet "TagID" matches GameObject "TagID" (in Hexadecimal) if (Convert.ToInt32(extractData[1]).ToString("X") == tagID) { gotCorrectPacket = true; } } } } while (!gotCorrectPacket); // Close OSC _OSCReceiver.Close(); } catch (Exception e) { Debug.Log(e.Message); } return(extractData); }
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(); //例外は上位に打ち上げる }
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(); }
//受信待受開始 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(); //例外は上位に打ち上げる }
void Awake() { // Log the start Debug.Log("Starting Osc Receiver"); // Ensure that the receiver is disconnected Disconnect(); // The address to listen on to IPAddress addess = IPAddress.Any; // The port to listen on int port = ListenPort; // Create an instance of the receiver m_Receiver = new OscReceiver(addess, port); // Connect the receiver m_Receiver.Connect(); // We are now connected Debug.Log("Connected Receiver"); }
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"); }
private static PortGroup CreateOrGetReceiverForPort(int port) { if (_groupsByPort.TryGetValue(port, out var receiver)) { return(receiver); } var newReceiver = new OscReceiver(port); newReceiver.Connect(); var newGroup = new PortGroup { Port = port, Receiver = newReceiver, }; var thread = new Thread(new ThreadStart(newGroup.ThreadProc)); newGroup.Thread = thread; thread.Start(); return(newGroup); }
static void Main(string[] args) { Console.WriteLine("OSC Server."); // 12345ポートでOscレシーバーを作成 using var oscReceiver = new OscReceiver(2345); // 接続処理 oscReceiver.Connect(); // 無限ループにして受信待ち while (true) { var oscPacket = oscReceiver.Receive(); var msg = oscPacket.ToString(); Console.WriteLine(msg); var f_t = msg.Split(" "); Console.WriteLine($"{f_t[0]} {f_t[1]} {f_t[2]}"); if (int.TryParse(f_t[1], out int freq) && int.TryParse(f_t[2], out int time)) { Console.Beep(freq, time); } } }
// Custom Constructor public OSCReader() { _OSCReceiver = new OscReceiver(_IPaddress, _PORT); _OSCReceiver.Connect(); }
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(); }