Passage serveur UDP OSC en Asynchrone (suppression ThreadLoop)
This commit is contained in:
parent
ea8ee8040a
commit
0a3b58f73d
1 changed files with 26 additions and 37 deletions
|
|
@ -3,6 +3,7 @@ using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace DMX2
|
namespace DMX2
|
||||||
{
|
{
|
||||||
|
|
@ -10,44 +11,39 @@ namespace DMX2
|
||||||
{
|
{
|
||||||
|
|
||||||
UdpClient udpCli=null;
|
UdpClient udpCli=null;
|
||||||
Thread pollThread = null;
|
|
||||||
bool running=true;
|
|
||||||
|
|
||||||
public OSCServer ()
|
public OSCServer ()
|
||||||
{
|
{
|
||||||
pollThread = new Thread(new ThreadStart(Loop));
|
udpCli = new UdpClient(7772);
|
||||||
pollThread.Start();
|
udpCli.BeginReceive(UdpCliReceive,null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Loop ()
|
void UdpCliReceive(IAsyncResult ar)
|
||||||
{
|
{
|
||||||
udpCli = new UdpClient (7772);
|
if (!ar.IsCompleted) return;
|
||||||
byte[] recv;
|
byte[] recv;
|
||||||
IPEndPoint remep = new IPEndPoint (IPAddress.Any, 0);
|
IPEndPoint remep = new IPEndPoint(IPAddress.Any, 0);
|
||||||
|
recv = udpCli.EndReceive(ar, ref remep);
|
||||||
|
|
||||||
try {
|
|
||||||
while (running) {
|
|
||||||
recv = udpCli.Receive (ref remep);
|
|
||||||
//Console.WriteLine(remep);
|
|
||||||
OSCMessage msg = new OSCMessage(recv);
|
OSCMessage msg = new OSCMessage(recv);
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
Console.Write(msg.Address);
|
Console.Write(msg.Address);
|
||||||
Console.Write(" ");
|
Console.Write(" ");
|
||||||
foreach(var arg in msg.Args)
|
foreach (var arg in msg.Args)
|
||||||
Console.WriteLine(arg.GetString());
|
Console.WriteLine(arg.GetString());
|
||||||
#endif
|
#endif
|
||||||
try{
|
try
|
||||||
ProcessMessage(msg,remep);
|
{
|
||||||
}catch{}
|
ProcessMessage(msg, remep);
|
||||||
}
|
|
||||||
} catch (SocketException ex) {
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
}
|
}
|
||||||
|
catch { }
|
||||||
|
udpCli.BeginReceive(UdpCliReceive, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// /master <X---
|
/// /master <X---
|
||||||
/// /masterseq/
|
/// /masterseq/
|
||||||
|
|
@ -347,15 +343,8 @@ namespace DMX2
|
||||||
protected virtual void Dispose (bool disposing)
|
protected virtual void Dispose (bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing) {
|
if (disposing) {
|
||||||
running=false;
|
|
||||||
if(udpCli!=null)
|
if(udpCli!=null)
|
||||||
udpCli.Close();
|
udpCli.Close();
|
||||||
if(pollThread!=null)
|
|
||||||
{
|
|
||||||
if(!pollThread.Join(100))
|
|
||||||
pollThread.Abort();
|
|
||||||
pollThread=null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue