Initial Commit

This commit is contained in:
2020-06-08 14:11:54 -05:00
commit 830e905300
24 changed files with 2129 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
using System;
using System.Net.Sockets;
using System.Net;
namespace SharpOSC
{
public class UDPSender
{
public int Port
{
get { return _port; }
}
int _port;
public string Address
{
get { return _address; }
}
string _address;
IPEndPoint RemoteIpEndPoint;
Socket sock;
public UDPSender(string address, int port)
{
_port = port;
_address = address;
sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
var addresses = System.Net.Dns.GetHostAddresses(address);
if (addresses.Length == 0) throw new Exception("Unable to find IP address for " + address);
RemoteIpEndPoint = new IPEndPoint(addresses[0], port);
}
public void Send(byte[] message)
{
sock.SendTo(message, RemoteIpEndPoint);
}
public void Send(OscPacket packet)
{
byte[] data = packet.GetBytes();
Send(data);
}
public void Close()
{
sock.Close();
}
}
}