public int Send(OSCPacket packet) { int byteNum = 0; byte[] data = packet.BinaryData; try { byteNum = this.udpClient.Send(data, data.Length); } catch (Exception e) { Console.Error.WriteLine(e.Message); Console.Error.WriteLine(e.StackTrace); } return byteNum; }
public int Send(OSCPacket packet) { int byteNum = 0; byte[] data = packet.BinaryData; try { byteNum = this.udpClient.Send(data, data.Length); } catch (Exception e) { Console.Error.WriteLine(e.Message); Console.Error.WriteLine(e.StackTrace); } return(byteNum); }
public OSCPacket Receive() { try { IPEndPoint ip = new IPEndPoint(IPAddress.Any, 0); byte[] bytes = this.udpClient.Receive(ref ip); if (bytes != null && bytes.Length > 0) { return(OSCPacket.Unpack(bytes)); } } catch (Exception e) { Console.WriteLine(e.Message); return(null); } return(null); }
/// <summary> /// Convert the Osc Time Tag to a byte array. /// </summary> /// <returns>A byte array containing the Osc Time Tag.</returns> public byte[] ToByteArray() { List <byte> timeStamp = new List <byte>(); byte[] secondsSinceEpoch = BitConverter.GetBytes(SecondsSinceEpoch); byte[] fractionalSecond = BitConverter.GetBytes(FractionalSecond); if (BitConverter.IsLittleEndian) // != OscPacket.LittleEndianByteOrder) { secondsSinceEpoch = OSCPacket.swapEndian(secondsSinceEpoch); fractionalSecond = OSCPacket.swapEndian(fractionalSecond); } timeStamp.AddRange(secondsSinceEpoch); timeStamp.AddRange(fractionalSecond); return(timeStamp.ToArray()); }
public static new OSCBundle Unpack(byte[] bytes, ref int start, int end, bool extendedMode = false) { string address = unpackString(bytes, ref start); //Console.WriteLine("bundle: " + address); if (!address.Equals(BUNDLE)) { return(null); // TODO } DateTime timestamp = unpackTimeTag(bytes, ref start); OSCBundle bundle = new OSCBundle(timestamp, extendedMode); while (start < end) { int length = unpackInt(bytes, ref start); int sub_end = start + length; bundle.Append(OSCPacket.Unpack(bytes, ref start, sub_end, extendedMode)); } return(bundle); }
public static new OSCBundle Unpack(byte[] bytes, ref int start, int end) { OSCBundle bundle = new OSCBundle(); string address = unpackString(bytes, ref start); if (!address.Equals(BUNDLE)) { return(null); // TODO } long time = unpackLong(bytes, ref start); while (start < end) { int subEnd = unpackInt(bytes, ref start); bundle.Append(OSCPacket.Unpack(bytes, ref start, subEnd)); } return(bundle); }
public static new OSCBundle Unpack(byte[] bytes, ref int start, int end) { string address = unpackString(bytes, ref start); //Console.WriteLine("bundle: " + address); if (!address.Equals(BUNDLE)) { return(null); // TODO } long timestamp = unpackLong(bytes, ref start); OSCBundle bundle = new OSCBundle(timestamp); while (start < end) { int length = unpackInt(bytes, ref start); int sub_end = start + length; //Console.WriteLine(bytes.Length +" "+ start+" "+length+" "+sub_end); bundle.Append(OSCPacket.Unpack(bytes, ref start, sub_end)); } return(bundle); }
/// <summary> /// EndReceive paired call. /// </summary> /// <param name="asyncResult">Paired result object from the BeginReceive call.</param> private void EndReceive(IAsyncResult asyncResult) { try { UdpState udpState = (UdpState)asyncResult.AsyncState; UdpClient udpClient = udpState.Client; IPEndPoint ipEndPoint = udpState.IPEndPoint; byte[] data = udpClient.EndReceive(asyncResult, ref ipEndPoint); if (data != null && data.Length > 0) { if (cb != null) { cb(OSCPacket.Unpack(data)); } } udpClient.BeginReceive(mAsyncCallback, udpState); } catch (ObjectDisposedException) { // Suppress error } }
private void receive() { while (true) { OSCPacket msg = receiver.Receive(); textBoxRecieveAddress.Text = msg.Address; ArrayList objs = msg.Values; string data = ""; bool first = true; foreach (object obj in objs) { if (first) { first = false; } else { data += ", "; } data += obj.ToString(); } textBoxRecieveData.Text = data; } }
public int Send(OSCPacket packet) { int byteNum = 0; byte[] data; try { if (!portIsTcp) { data = packet.BinaryData; byteNum = this.udpClient.Send(data, data.Length); } else { OSCBundle bundle = packet as OSCBundle; if (bundle != null) { foreach (var value in bundle.Values) { if (value is OSCMessage) { OSCMessage message = value as OSCMessage; XmlElement xmlMessage = message.ToXml; //<OSCPACKET ADDRESS="127.0.0.1" PORT="49178" TIME="1"> XmlDocument xDoc = new XmlDocument(); XmlElement xmlPacket = xDoc.CreateElement("OSCPACKET"); XmlAttribute address = xDoc.CreateAttribute("ADDRESS"); address.Value = "127.0.0.1"; XmlAttribute port = xDoc.CreateAttribute("PORT"); port.Value = "0"; XmlAttribute time = xDoc.CreateAttribute("TIME"); time.Value = "0"; xmlPacket.Attributes.Append(address); xmlPacket.Attributes.Append(port); xmlPacket.Attributes.Append(time); xDoc.AppendChild(xmlPacket); xmlPacket.AppendChild(xDoc.ImportNode(xmlMessage, true)); String xml = xDoc.InnerXml; //Console.Write(xml); this.tcpServer.Broadcast(xDoc); } } } } } catch (Exception e) { Console.Error.WriteLine(e.Message); Console.Error.WriteLine(e.StackTrace); } return byteNum; }
public int Send(OSCPacket packet) { int byteNum = 0; byte[] data; try { if (!portIsTcp) { data = packet.BinaryData; byteNum = this.udpClient.Send(data, data.Length); } else { OSCBundle bundle = packet as OSCBundle; if (bundle != null) { foreach (var value in bundle.Values) { if (value is OSCMessage) { OSCMessage message = value as OSCMessage; XmlElement xmlMessage = message.ToXml; //<OSCPACKET ADDRESS="127.0.0.1" PORT="49178" TIME="1"> XmlDocument xDoc = new XmlDocument(); XmlElement xmlPacket = xDoc.CreateElement("OSCPACKET"); XmlAttribute address = xDoc.CreateAttribute("ADDRESS"); address.Value = "127.0.0.1"; XmlAttribute port = xDoc.CreateAttribute("PORT"); port.Value = "0"; XmlAttribute time = xDoc.CreateAttribute("TIME"); time.Value = "0"; xmlPacket.Attributes.Append(address); xmlPacket.Attributes.Append(port); xmlPacket.Attributes.Append(time); xDoc.AppendChild(xmlPacket); xmlPacket.AppendChild(xDoc.ImportNode(xmlMessage, true)); String xml = xDoc.InnerXml; //Console.Write(xml); this.tcpServer.Broadcast(xDoc); } } } } } catch (Exception e) { Console.Error.WriteLine(e.Message); Console.Error.WriteLine(e.StackTrace); } return(byteNum); }