private void MessageReceiveLoopOnException(ISocket socket, Exception exception) { try { ResponseException(socket, exception); } catch { } socket.Disconnect(); }
/// <summary> /// 断开链接 /// </summary> public void Disconnect() { lock (syncRoot) { socket.Disconnect(); } }
private bool ProcessDeletePeerMessage(IMessage message, ISocket socket) { var shouldHandle = message.Equals(KinoMessages.DeletePeer); if (shouldHandle) { var payload = message.GetPayload <DeletePeerMessage>(); var socketIdentifier = new ReceiverIdentifier(payload.NodeIdentity); var meta = connectedPeerRegistry.Find(socketIdentifier); if (meta != null) { connectedPeerRegistry.Remove(socketIdentifier); logger.Debug($"Left {connectedPeerRegistry.Count()} nodes to monitor."); if (meta.ConnectionEstablished) { socket.Disconnect(new Uri(meta.HealthUri)); logger.Warn($"Stopped HeartBeat monitoring node {payload.NodeIdentity.GetAnyString()}@{meta.HealthUri}"); } } else { logger.Warn($"Unable to disconnect from unknown node [{payload.NodeIdentity.GetAnyString()}]"); } } return(shouldHandle); }
private bool ProcessHeartBeatMessage(IMessage message, ISocket socket) { var shouldHandle = message.Equals(KinoMessages.HeartBeat); if (shouldHandle) { var payload = message.GetPayload <HeartBeatMessage>(); var socketIdentifier = new ReceiverIdentifier(payload.SocketIdentity); var meta = connectedPeerRegistry.Find(socketIdentifier); if (meta != null) { meta.LastKnownHeartBeat = DateTime.UtcNow; //logger.Debug($"Received HeartBeat from node {socketIdentifier}"); } else { //TODO: Send DiscoveryMessage? What if peer is not supporting message Domains to be used by this node? logger.Warn($"HeartBeat came from unknown node {payload.SocketIdentity.GetAnyString()}. Will disconnect from HealthUri: {payload.HealthUri}"); try { socket.Disconnect(new Uri(payload.HealthUri)); } catch (Exception err) { logger.Error(err); } } } return(shouldHandle); }
public void Disconnect(Object state) { if (socket != null) { socket.Disconnect(state); } }
public void ConnectAsyncIPV6CallbackTest() { ManualResetEventSlim mevent = new ManualResetEventSlim(false); mevent.Reset(); try { ipv6Protocol.Listen(); UdpProtocol ipvClient = this.CreateIPV6ClientProtocol(ipv6ServerAddress); ISocket udpSocket = null; ipvClient.ConnectAsync((socket) => { udpSocket = socket; mevent.Set(); }, ipv6ServerAddress, PORT); Assert.IsTrue(mevent.Wait(10000), "Connection never triggered callback."); sockets.Add(udpSocket); Assert.IsNotNull(udpSocket, "Callback did not receive a socket."); Assert.IsTrue(udpSocket.Connected, "A connection could not be established."); udpSocket.Disconnect(); } catch (Exception ex) { Assert.Fail(ex.ToString()); } }
public void TestCleanup() { ipv4Client.Disconnect(); ipv6Client.Disconnect(); ipv4Server.StopListening(); ipv4Server.Dispose(); ipv6Server.StopListening(); ipv6Server.Dispose(); }
protected override void Dispose(bool disposing) { if (m_isConnected) { m_socket.Disconnect(false); } m_isConnected = false; m_isConnecting = false; m_socket.Dispose(); }
public static void SafeDisconnect(this ISocket socket, Uri uri) { try { socket.Disconnect(uri); } catch (EndpointNotFoundException) { } }
protected virtual bool HandlePending(ISocket socket) { lock (pending) { var conn = pending.Find((s) => s.Socket == socket); if (conn == null) { socket.Disconnect(); return(false); } pending.Remove(conn); } return(true); }
/// <inheritdoc /> public void Close() { // we need to lock the close method // otherwise multiple concurrent calls to Close will cause the OnDisconnected to be called twice lock (this) { if (IsClosed) { return; } try { _logger.LogInformation($"Dispose was called on client: {Id}"); // mark as disposed IsClosed = true; // complete the channel _queue.Writer.TryComplete(); // cancelling the receive cancellation token _cancellationTokenSource.Cancel(); // setting status for all the tickets SetStatusForAllPendingTickets(); // disconnect the socket if (_socket.Connected) { _socket.Disconnect(); } // we need to invoice OnDisconnected on a separate thread ThreadPool.QueueUserWorkItem(_ => { var disconnectedEventArgs = new ClientSessionDisconnectedEventArgs { Id = Id }; OnDisconnected?.Invoke(this, disconnectedEventArgs); OnDisconnected = null; }); } catch { // no-op } } }
private static void ProcessInput(string input) { if (input.Trim().ToLower() == "--stop" || input.Trim().ToLower() == "--quit") { running = false; if (client != null && client.Connected) { client.Disconnect(); } return; } var sent = client?.Send(Encoding.UTF8.GetBytes(input)); Console.WriteLine($"{sent} bytes sent."); }
public void Disconnect(Object state) { /* * if (LoggedIn) { * logged = false; * * server.History.Add(this); * * server.SendPacket((s) => * s.Vroom == vroom, * new Parted(name)); * } */ if (socket != null) { socket.Disconnect(state); } }
public void TestCleanup() { ipv4Client.Disconnect(); ipv6Client.Disconnect(); foreach (ISocket socket in sockets) { socket?.Disconnect(); } if (ipv4Server.Listening) { ipv4Server.StopListening(); } ipv4Server.Dispose(); if (ipv6Server.Listening) { ipv6Server.StopListening(); } ipv6Server.Dispose(); }
static async Task SendSocketPolicy(ISocket socket) { await socket.SendBytesAsync(FlashSocketPolicyRequestHandler.FLASH_POLICY_RESPONSE); socket.Disconnect("Socket policy request"); }
public Task Disconnect() => _socket.Disconnect();
private void MessageReceiveLoopOnException(ISocket socket, Exception exception) { socket.Disconnect(); }
public void Disconnect() { _socket.Disconnect(); }
private void MessageReceiveLoopOnException(ISocket socket, Exception exception) { socket.Disconnect(); }
public void Disconnect() { _socketServer.Disconnect(); }
public override void Disconnect() { _connectionStatus = ConnectionStatus.Disconnected; _socket.Disconnect(SocketService); }
private bool UnregisterRoute(IMessage message, ISocket scaleOutBackend) { var shouldHandle = IsUnregisterRouting(message); if (shouldHandle) { var payload = message.GetPayload<UnregisterNodeMessageRouteMessage>(); externalRoutingTable.RemoveNodeRoute(new SocketIdentifier(payload.SocketIdentity)); try { scaleOutBackend.Disconnect(new Uri(payload.Uri)); } catch (EndpointNotFoundException) { } } return shouldHandle; }
private bool ForwardMessageAway(MessageIdentifier messageIdentifier, Message message, ISocket scaleOutBackend) { var handlers = ((message.Distribution == DistributionPattern.Unicast) ? new[] {externalRoutingTable.FindRoute(messageIdentifier)} : (MessageCameFromLocalActor(message) ? externalRoutingTable.FindAllRoutes(messageIdentifier) : Enumerable.Empty<Node>())) .Where(h => h != null) .ToList(); foreach (var handler in handlers) { try { message.SetSocketIdentity(handler.SocketIdentity); message.PushRouterAddress(routerConfiguration.ScaleOutAddress); scaleOutBackend.SendMessage(message); messageTracer.ForwardedToOtherNode(message); } catch (HostUnreachableException err) { externalRoutingTable.RemoveNodeRoute(new SocketIdentifier(handler.SocketIdentity)); scaleOutBackend.Disconnect(handler.Uri); logger.Error(err); } } return handlers.Any(); }
private void btnDisconnect_Click(object sender, EventArgs e) { _socket.Disconnect(); //SetStatus(_server.IsConnected); }
private void MessageReceiveLoopOnException(ISocket socket, Exception exception) { try { ResponseException(socket, exception); } catch { } socket.Disconnect(); }