soundvision/UnityProject/Assets/Scripts/PdConnection/PdSender.cs

32 lines
653 B
C#
Raw Normal View History

2019-10-01 13:08:35 +00:00
using System;
using System.Net;
using System.Net.Sockets;
namespace cylvester
{
2019-10-05 12:18:52 +00:00
public interface IPdSender : IDisposable
2019-10-01 13:08:35 +00:00
{
void Send(byte[] bytes);
}
2019-10-05 12:18:52 +00:00
public class PdSender : IPdSender
2019-10-01 13:08:35 +00:00
{
private Socket socket_;
2019-10-05 12:18:52 +00:00
public PdSender(string ip, int port)
2019-10-01 13:08:35 +00:00
{
socket_ = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
socket_.Connect(IPAddress.Parse(ip), port);
}
public void Send(byte[] bytes)
{
socket_.Send(bytes);
}
public void Dispose()
{
socket_.Close();
}
}
}