mirror of
https://github.com/jwetzell/QControlKit.git
synced 2026-08-10 18:03:45 +00:00
Initial Commit
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user