public static GetPacket ( byte OscData ) : |
||
OscData | byte | |
리턴 |
void ReceiveCallback(IAsyncResult result) { Monitor.Enter(callbackLock); Byte[] bytes = null; IPEndPoint remoteEP = null; try { bytes = receivingUdpClient.EndReceive(result, ref remoteEP); } catch (ObjectDisposedException e) { // Ignore if disposed. This happens when closing the listener } // Process bytes if (bytes != null && bytes.Length > 0) { if (BytePacketCallback != null) { BytePacketCallback(bytes); } else if (OscPacketCallback != null) { OscPacket packet = null; try { packet = OscPacket.GetPacket(bytes, remoteEP); } catch (Exception e) { // If there is an error reading the packet, null is sent to the callback } OscPacketCallback(packet); } else { lock (queue) { queue.Enqueue(bytes); } } } if (closing) { ClosingEvent.Set(); } else { // Setup next async event AsyncCallback callBack = new AsyncCallback(ReceiveCallback); receivingUdpClient.BeginReceive(callBack, remoteEP); } Monitor.Exit(callbackLock); }
void ReceiveCallback(IAsyncResult result) { Monitor.Enter(callbackLock); Byte[] bytes = null; try { bytes = receivingUdpClient.EndReceive(result, ref RemoteIpEndPoint); } finally { } // Process bytes if (bytes != null && bytes.Length > 0) { if (BytePacketCallback != null) { BytePacketCallback(bytes); } else if (OscPacketCallback != null) { OscPacket packet = null; try { packet = OscPacket.GetPacket(bytes); } finally { } OscPacketCallback(packet); } else { lock (queue) { queue.Enqueue(bytes); } } } if (closing) { ClosingEvent.Set(); } else { // Setup next async event AsyncCallback callBack = new AsyncCallback(ReceiveCallback); receivingUdpClient.BeginReceive(callBack, null); } Monitor.Exit(callbackLock); }
public OscPacket Receive() { if (closing) { throw new Exception("UDPListener has been closed."); } lock (queue) { if (queue.Count() > 0) { byte[] bytes = queue.Dequeue(); var packet = OscPacket.GetPacket(bytes); return(packet); } else { return(null); } } }