private void Receive() { Message message = null; while (!_requestStop) { message = _transceiver.Receive(); if (message != null) { switch (message.Code) { case (Int32)SystemMessageCode.TaskOverEvent: { Terminate(); TaskOverEventArgs args = message.GetContent <TaskOverEventArgs>(); OnTaskOver(args); } break; case (Int32)SystemMessageCode.ActivatorErrorEvent: { Terminate(); ActivatorErrorEventArgs args = message.GetContent <ActivatorErrorEventArgs>(); OnActivatorError(args); } break; default: ReceiveCallback?.Invoke(message); break; } } } }
private async Task Receive() { string overflow = ""; while (ws.State == WebSocketState.Open) { var buffer = new byte[BufferSize]; var result = await ws.ReceiveAsync(new ArraySegment <byte>(buffer), CancellationToken.None); while (!result.EndOfMessage) { overflow += Encoding.UTF8.GetString(buffer.TakeWhile((x) => x != 0).ToArray()); result = await ws.ReceiveAsync(new ArraySegment <byte>(buffer), CancellationToken.None); } overflow += Encoding.UTF8.GetString(buffer.TakeWhile((x) => x != 0).ToArray()); rc?.Invoke(overflow, state); overflow = ""; } rc?.Invoke("Disconnected", null); }
private void ProcessReceive(object sender, SocketAsyncEventArgs e) { logger?.Info($"Session.ProcessReceive: this={GetHashCode()}, e.SocketError={e?.SocketError}"); if (e.SocketError == SocketError.Success && 0 < e.BytesTransferred) { ReceiveCallback?.Invoke(sender, new SessionEventArgs { Text = Encoding.UTF8.GetString(e.Buffer, e.Offset, e.BytesTransferred), BytesTransferred = e.BytesTransferred }); StartReceive(); } else { CloseSocket(e); } }
protected void Listener() { while (!stop.WaitOne(0)) { System.Threading.Tasks.Task <UdpReceiveResult> t = udp.ReceiveAsync(); while (!t.Wait(100) && !stop.WaitOne(0)) { } if (t.Wait(0)) { byte[] datagram = t.Result.Buffer; IPEndPoint from = t.Result.RemoteEndPoint; if (datagram.Length > 0 && (broadcastToLocalhost || !localAddresses.Contains(from.Address))) { Threads.APC.MonoBehaviourCall.Instance.Call(() => onReceive.Invoke(from, datagram)); } } } }