private static async Task OpenSocket() { if (socket != null) { CloseSocket(); } try { if (App.isRPi) { await socket.ConnectAsync(new Uri($"ws://{App.ServiceUri}/camera/sender/?device=camera")); } else { await socket.ConnectAsync(new Uri($"ws://{App.ServiceUri}/camera/receiver/?device=camera")); } socketIsConnected = true; Debug.WriteLine("Camera web socket connected!"); } catch (Exception ex) { socket.Dispose(); socket = null; socketIsConnected = false; Debug.WriteLine("Error connecting to camera web socket: " + ex.Message); } }
private void Closed(IWebSocket sender, WebSocketClosedEventArgs args) { if (messageWebSocket != null) { messageWebSocket.Dispose(); socketSubject.OnCompleted(); messageWebSocket = null; } }
private void Closed(IWebSocket sender, WebSocketClosedEventArgs args) { System.Diagnostics.Debug.WriteLine("Closed; Code: " + args.Code + ", Reason: " + args.Reason); if (messageWebSocket != null) { messageWebSocket.Dispose(); messageWebSocket = null; } }
public Task <InvokeResult> CloseAsync() { if (_webSocket != null) { _webSocket.Close(1000, String.Empty); _webSocket.Dispose(); _webSocket = null; } return(Task.FromResult(InvokeResult.Success)); }
public void Reset() { lock (this) { if (readPacket != null) { try { readPacket.DetachStream(); readPacket = null; } catch (Exception exp) { Diag.DebugPrint("Could not detach DataReader: " + exp.Message); } } if (writePacket != null) { try { writePacket.DetachStream(); writePacket = null; } catch (Exception exp) { Diag.DebugPrint("Could not detach DataWriter: " + exp.Message); } } if (socket != null) { socket.Dispose(); socket = null; } if (channel != null) { if (((IDictionary <string, object>)CoreApplication.Properties).ContainsKey(channel.ControlChannelTriggerId)) { CoreApplication.Properties.Remove(channel.ControlChannelTriggerId); } // Call the Dispose() method on the controlchanneltrigger object to release any // OS maintained resources for this channel object. channel.Dispose(); channel = null; } Diag.DebugPrint("CommModule has been reset."); } }
protected override void DoClose() { if (ws != null) { try { ws.Closed -= ws_Closed; //ws.MessageReceived -= ws_MessageReceived; if (dataWriter != null) { dataWriter.Dispose(); dataWriter = null; } ws.Close(1000, "DoClose"); ws.Dispose(); ws = null; } catch (Exception e) { var log = LogManager.GetLogger(Global.CallerName()); log.Info("DoClose ws.Close() Exception= " + e.Message); } } }
public static async Task RestartSocket() { socket = new MessageWebSocket(); socket.MessageReceived += MessageWebSocket_MessageReceived; socket.Closed += MessageWebSocket_Closed; socket.Control.MessageType = SocketMessageType.Binary; try { if (App.isRPi) { await socket.ConnectAsync(new Uri($"ws://{App.ServiceUri}/camera/sender/?device=camera")); } else { await socket.ConnectAsync(new Uri($"ws://{App.ServiceUri}/camera/receiver/?device=camera")); } socketIsConnected = true; Debug.WriteLine("Camera web socket restarted!"); } catch (Exception ex) { socket.Dispose(); socket = null; socketIsConnected = false; Debug.WriteLine("Error restarting camera web socket: " + ex.Message); } }
public void Disconnect() { //Killing connection messageWebSocket.Dispose(); messageWebSocket = null; Con = false; }
public override async void DisconnectAsync(string msg = "Powered by WinIRC", bool attemptReconnect = false) { WriteLine("QUIT :" + msg); IsConnected = false; if (attemptReconnect) { IsConnecting = true; if (ConnCheck.HasInternetAccess) { ReconnectionAttempts++; await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, async() => { if (ReconnectionAttempts < 3) { await Task.Delay(1000); } else { await Task.Delay(60000); } Connect(); }); } } else { HandleDisconnect?.Invoke(this); messageWebSocket.Dispose(); } }
public override void Disconnect(string msg = "Powered by WinIRC") { WriteLine("QUIT :" + msg); HandleDisconnect(this); messageWebSocket.Dispose(); }
public void DisposeSocket() { socket.Dispose(); socket = new MessageWebSocket(); socket.MessageReceived += OnMessageReceived; guid = Guid.NewGuid().ToString(); }
private async Task ConnectToWebSocket() { var rnd = new Random().Next(40) + 50; string server = "ws://" + ws_server + ":80" + rnd; Uri serverConnect = new Uri(server); if (serverConnect == null) { return; } messageWebSocket = new MessageWebSocket(); messageWebSocket.Control.MessageType = SocketMessageType.Utf8; messageWebSocket.MessageReceived += MessageReceived; messageWebSocket.Closed += OnClosed; try { await messageWebSocket.ConnectAsync(serverConnect); } catch (Exception ex) // For debugging { // Error happened during connect operation. messageWebSocket.Dispose(); messageWebSocket = null; Debug.WriteLine(ex); return; } messageWriter = new DataWriter(messageWebSocket.OutputStream); await SendAsync(); }
private void Connection_Closed(IWebSocket sender, WebSocketClosedEventArgs args) { MessageWebSocket webSocket = Interlocked.Exchange(ref _connection, null); webSocket?.Dispose(); ConnectionClosed = true; }
public void Unsubscribe() { if (webSocket != null) { webSocket.Dispose(); webSocket = null; } }
private void Dispose() { dataWriter.Dispose(); dataWriter = null; socket.Dispose(); socket = null; isAttached = false; isOpened = false; }
// Close connection private void Closed(IWebSocket sender, WebSocketClosedEventArgs args) { MessageWebSocket webSocket = Interlocked.Exchange(ref messageWebSocket, null); if (webSocket != null) { webSocket.Dispose(); } }
public static void Dispose() { _reconnectTimer?.Cancel(); _timer?.Cancel(); if (_socket != null) { _socket.Dispose(); _socket = null; } }
public void Close() { if (WebSocket != null) { WebSocket.Dispose(); WebSocket = null; isAlive = false; OnClosed?.Invoke(null, EventArgs.Empty); } }
public override void Dispose() { try { messageWebSocket.Dispose(); } catch (Exception e) { OnError?.Invoke("Dispose:" + e.Message); } }
private void CreateSocket() { _socket?.Dispose(); _socket = new MessageWebSocket(); _socket.Control.MessageType = SocketMessageType.Utf8; _socket.MessageReceived += HandleMessage; _socket.Closed += HandleClosed; _dataWriter?.Dispose(); _dataWriter = new DataWriter(_socket.OutputStream); }
void EndConnection() { if (_websocket != null) { _websocket.Dispose(); _websocket = null; IsOpen = false; OnClosed(); } }
public static async Task OpenSocket(string f, string t) { if (socket != null) { CloseSocket(); } Init(); from = f; to = t; try { await socket.ConnectAsync(new Uri($"ws://{App.ServiceUri}/ws/?from={from}&to={to}")); socketIsConnected = true; if (!App.isRPi) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { var currentPage = ((ContentControl)Window.Current.Content).Content as Page; var serviceStatus = currentPage.FindName("serviceStatus") as Image; serviceStatus.Opacity = 1; }); } else { Debug.WriteLine("Web socket connected!"); } } catch (Exception ex) { socket.Dispose(); socket = null; socketIsConnected = false; Debug.WriteLine("Error connecting to web socket: " + ex.Message); HandleException(ex.Message); } }
void CloseSocket() { Logger.Debug("Signaling", "CloseSocket"); if (socket == null) { Logger.Debug("Signaling", "CloseSocket - already closed"); return; } socket.Dispose(); socket = null; }
void mws_Closed(IWebSocket sender, WebSocketClosedEventArgs args) { MessageWebSocket websocket = Interlocked.Exchange(ref mws, null); if (websocket != null) { websocket.Dispose(); } //if(this.mwsState == WebSocketState.Closing) this.OnSocketConnectionClosedEvent(this, EventArgs.Empty); this.mwsState = WebSocketState.Closed; }
/// <summary> /// クライアント機能を停止 /// </summary> public void DisconnectServer() { #if UNITY_UWP ws.MessageReceived -= MessageReceived; ws.Dispose(); ws = null; #elif UNITY_EDITOR || UNITY_STANDALONE ws.OnMessage -= OnMessage; ws.Close(); ws = null; #endif }
/// <summary> /// Idempotent. /// </summary> protected override void CloseSocket() { try { // the writer is null if the connection has never been successfully opened if (writer != null) { writer.Dispose(); } ws.Close(1000, "Closed by client."); ws.Dispose(); } catch (Exception) { } }
void EndConnection() { if (_websocket != null) { _websocket.Closed -= _websocket_Closed; _websocket.MessageReceived -= _websocket_MessageReceived; _websocket.Dispose(); _websocket = null; IsOpen = false; OnClosed(); } }
/// <summary> /// Stops listening for bridge events. /// </summary> public void StopStream() { if (running) { running = false; clientWriter.Dispose(); client.Close(1000, "Closed"); client.Dispose(); } else { throw new InvalidOperationException("Bridge stream is already stopped."); } }
public void Close() { if (pending != null) { pending.Dispose(); pending = null; } if (streamWebSocket != null) { streamWebSocket.Close(1000, "Normal closure"); streamWebSocket.Dispose(); streamWebSocket = null; } }
public void Dispose() { _isDisposed = true; _messageWriter.Dispose(); _webSocket.Dispose(); lock (_gate) { foreach (var callback in _callbacks) { // Set null rather than cancelling to prevent exception callback.Value.TrySetResult(null); } } }