soundvision/UnityProject/Assets/Scripts/PdConnection/PdReceiver.cs
Chikashi Miyama d00d95859f refer #60
2019-10-05 14:18:52 +02:00

35 lines
No EOL
799 B
C#

using System;
using System.Net;
using System.Net.Sockets;
namespace cylvester
{
public interface IPdReceiver
{
event Action<byte[]> DataReceived;
void Update();
}
public class PdReceiver : IPdReceiver
{
private readonly UdpClient udpClient_;
private IPEndPoint remote_;
public PdReceiver(int port)
{
udpClient_ = new UdpClient(port);
remote_ = new IPEndPoint(IPAddress.Any, port);
}
public void Update()
{
while (udpClient_.Available > 0)
{
var receivedData = udpClient_.Receive(ref remote_);
DataReceived?.Invoke(receivedData);
}
}
public event Action<byte[]> DataReceived;
}
}