public static extern void HP_Set_FN_Client_OnClose(IntPtr pListener, OnClose fn);
/// <summary> /// 点击取消按钮回调此方法 /// </summary> private Task OnClickClose() { CurrentTime = Value; OnClose?.Invoke(); return(Task.CompletedTask); }
private async Task receiveLoop() { byte[] buffer = new byte[websocket_package_size]; while (true) { string json = string.Empty; System.Net.WebSockets.WebSocketReceiveResult result; try { if (ws == null) { return; } if (ws.State != System.Net.WebSockets.WebSocketState.Open) { OnClose?.Invoke(""); return; } result = await ws.ReceiveAsync(new ArraySegment <byte>(buffer), src.Token); json = Encoding.UTF8.GetString(buffer.Take(result.Count).ToArray()); if (TryParseJSON(json)) { var message = JsonConvert.DeserializeObject <SocketMessage>(json); if (message != null) { _receiveQueue.Add(message); } } else { if (TryParseJSON(tempbuffer + json)) { var message = JsonConvert.DeserializeObject <SocketMessage>(tempbuffer + json); if (message != null) { _receiveQueue.Add(message); } tempbuffer = null; } else { if (!string.IsNullOrEmpty(tempbuffer)) { Log.Debug("FAILED: " + json); } tempbuffer += json; } if (!string.IsNullOrEmpty(tempbuffer) && tempbuffer.Length > (websocket_package_size * 2)) { tempbuffer = null; } } await ProcessQueue(); } catch (System.Net.WebSockets.WebSocketException ex) { if (ws.State != System.Net.WebSockets.WebSocketState.Open) { OnClose?.Invoke(ex.Message); } else { if (!string.IsNullOrEmpty(json)) { Log.Error(json); } Log.Error(ex, ""); await Task.Delay(3000); await this.Close(); } } catch (Exception ex) { if (ws.State != System.Net.WebSockets.WebSocketState.Open) { OnClose?.Invoke(ex.Message); } else { if (!string.IsNullOrEmpty(json)) { Log.Error(json); } Log.Error(ex, ""); await Task.Delay(3000); //await this.Close(); } } } }
private void Listen() { while (!dispose) { var buffers = new List <byte[]>(); WebSocketReceiveResult msgInfo = null; try { while (!msgInfo?.EndOfMessage ?? true) { var b = new ArraySegment <byte>(new byte[bufferSize]); msgInfo = socket.ReceiveAsync(b, socketTokenSource.Token).Result; var bArray = b.Array; Array.Resize(ref bArray, msgInfo.Count); buffers.Add(bArray); } } catch (AggregateException ex) when(ex.InnerException?.GetType() == typeof(TaskCanceledException)) { _ = OnClose.InvokeAsync(); return; } catch (Exception e1) { OnError?.Invoke(e1); if (!AutoReconnect) { return; } try { _ = socketTokenSource.Token.WaitHandle.WaitOne(1000); ConnectAsync().Wait(); } catch (Exception e2) { _ = OnReconnectFailed.InvokeAsync(); _ = OnError.InvokeAsync(e2); _ = OnClose.InvokeAsync(); } return; } var buffer = new List <byte>(); foreach (var b in buffers) { buffer.AddRange(b); } _ = Task.Run(() => HandleNewMessage(msgInfo, buffer.ToArray())); } _ = OnClose.InvokeAsync(); }
public void Close() { OnClose?.Invoke(this, true); ws.Dispose(); }
private void FormLogin_FormClosed(object sender, FormClosedEventArgs e) { OnClose?.Invoke(); }
private void CloseError(Socket socket, Exception exception) { OnError.Invoke(this, exception); OnClose.Invoke(this, null); Console.WriteLine($"TCPClient: Unexpectadely disconnected. {exception.Message}"); }
/// <summary> /// Closes the modal and invokes the <see cref="OnClose"/> event. /// </summary> public void Cancel() { CloseModal?.Invoke(); OnClose?.Invoke(ModalResult.Cancel(_modalType)); }
/// <summary> /// Closes the modal and invokes the <see cref="OnClose"/> event with the specified <paramref name="modalResult"/>. /// </summary> /// <param name="modalResult"></param> public void Close(ModalResult modalResult) { modalResult.ModalType = _modalType; CloseModal?.Invoke(); OnClose?.Invoke(modalResult); }
public void SetAsLoaded() { // loading = false; OnClose?.Invoke(); }
private void cmdClose_Click(object sender, EventArgs e) { OnClose?.Invoke(this, EventArgs.Empty); }
public void InvokeClose() { Connected = false; OnClose?.Invoke(); }
private void ClientDisconnectError(Socket socket, Exception exception) { OnError.Invoke(this, exception); OnClose.Invoke(this, socket); Console.WriteLine($"TCPServer: Client unexpectadely disconnected. {exception.Message}"); }
/// <summary> /// 点击取消按钮回调此方法 /// </summary> protected void OnClickClose() { CurrentTime = Value; OnClose?.Invoke(); }
public virtual void Close(CloseReason reason) { OnClose?.Invoke(reason); CyberFuck.netPlay?.SendMessage(MessageContentType.CloseConnection, world.NetType == NetType.Server ? -1 : world.MyPlayerId, null); }
protected virtual void Close() { OnClose?.Invoke(this, EventArgs.Empty); }
public void Close() { OnClose?.Invoke(); }
protected override void OnClosed(EventArgs e) { OnClose?.Invoke(this, e); base.OnClosed(e); }
public void Closed(IWebSocket webSocket, WebSocketClosedEventArgs args) { // OnClose.Invoke(args.Reason); OnClose?.Invoke(true); // TODO: detect if disconnect was clean }
public void Close() { isOpen = false; OnClose?.Invoke(); }
protected void RaiseOnClose(bool result) { OnClose.SafeInvoke(result); }
public void ListenClose(OnClose onMultiCastMsg) { this.onClose = onMultiCastMsg; }
internal void InvokeOnClose() { OnClose?.Invoke(); }
/// <summary> /// Dequeues all the messages from Discord and invokes appropriate methods. This will process the message and update the internal state before invoking the events. Returns the messages that were invoked and in the order they were invoked. /// </summary> /// <returns>Returns the messages that were invoked and in the order they were invoked.</returns> public IMessage[] Invoke() { //Dequeue all the messages and process them IMessage[] messages = connection.DequeueMessages(); for (int i = 0; i < messages.Length; i++) { //Do a bit of pre-processing var message = messages[i]; HandleMessage(message); //Invoke the appropriate methods switch (message.Type) { case MessageType.Ready: if (OnReady != null) { OnReady.Invoke(this, message as ReadyMessage); } break; case MessageType.Close: if (OnClose != null) { OnClose.Invoke(this, message as CloseMessage); } break; case MessageType.Error: if (OnError != null) { OnError.Invoke(this, message as ErrorMessage); } break; case MessageType.PresenceUpdate: if (OnPresenceUpdate != null) { OnPresenceUpdate.Invoke(this, message as PresenceMessage); } break; case MessageType.Subscribe: if (OnSubscribe != null) { OnSubscribe.Invoke(this, message as SubscribeMessage); } break; case MessageType.Unsubscribe: if (OnUnsubscribe != null) { OnUnsubscribe.Invoke(this, message as UnsubscribeMessage); } break; case MessageType.Join: if (OnJoin != null) { OnJoin.Invoke(this, message as JoinMessage); } break; case MessageType.Spectate: if (OnSpectate != null) { OnSpectate.Invoke(this, message as SpectateMessage); } break; case MessageType.JoinRequest: if (OnJoinRequested != null) { OnJoinRequested.Invoke(this, message as JoinRequestMessage); } break; case MessageType.ConnectionEstablished: if (OnConnectionEstablished != null) { OnConnectionEstablished.Invoke(this, message as ConnectionEstablishedMessage); } break; case MessageType.ConnectionFailed: if (OnConnectionFailed != null) { OnConnectionFailed.Invoke(this, message as ConnectionFailedMessage); } break; default: //This in theory can never happen, but its a good idea as a reminder to update this part of the library if any new messages are implemented. Logger.Error("Message was queued with no appropriate handle! {0}", message.Type); break; } } //Finally, return the messages return(messages); }
public void NetworkClose(ISocket socket) { Disconencted(); OnClose?.Invoke(this); }
protected override void OnDisable() { base.OnDisable(); OnClose?.Invoke(); }
void ClearOnClose() { onClose = null; }
public void Cancel() { OnClose?.Invoke(ModalResult.Cancel()); }
private void _onClose() { // stop the timer while normally closing the connection _timer.Stop(); OnClose?.Invoke(); }
public void Close(ModalResult modalResult) { OnClose?.Invoke(modalResult); }
public static extern void HP_Set_FN_Server_OnClose(IntPtr pListener, OnClose fn);
public override async Task CloseAsync() { client.Close(); OnClose?.Invoke(this, new ChannelCloseEventArgs(Id)); await Task.CompletedTask; }