/// <summary> /// Removes the tunnel from the server and closes all connections. /// </summary> /// <param name="tunnel">The tunnel to be removed.</param> /// <param name="notifyServer">if set to <c>true</c> then notify the server of the closure.</param> protected virtual async Task RemoveTunnelAsync(ClientTunnel tunnel, bool notifyServer) { if (Tunnels.TryRemove(tunnel.Id, out var _)) { if (notifyServer) { var message = new Message { Type = MessageType.Notification, Code = MessageCode.CloseTunnelMessage }; message.Values["tunnel_id"] = tunnel.Id; await SendMessageAsync(message, CancellationToken.None); } var connections = Connections.Values.Where(a => a.TunnelId == tunnel.Id).ToList(); foreach (var connection in connections) { await RemoveConnectionAsync(connection, false); } await tunnel.CloseLocalAsync(); } }
public void initializeClients() { int clientsConnected = 0; for (int i = 0; i < tunnelSystem.Length; i++) { if (tunnelSystem[i] == null) { tunnelSystem[i] = new ClientTunnel(_serverIp, _serverSocket); if (tunnelSystem[i].isConnected()) { clientsConnected++; } } } if (clientsConnected == tunnelSystem.Length) { MessageBox.Show("all connected"); initializeBackgroundComs(); } else { for (int i = 0; i < tunnelSystem.Length; i++) { tunnelSystem[i] = null; } } }
private void readCurrentPos() { ClientTunnel tempClient = getNextClient(); CurrentPos = new E6Pos(tempClient.readVariable("$POS_ACT")); tempClient.IsActive = false; CurrentPos.updateCurrentE6Pos(ref _globalCoordinates); }
private void readCurrentAxis() { ClientTunnel tempClient = getNextClient(); CurrentAxis = new E6Axis(tempClient.readVariable("$AXIS_ACT_MEAS")); tempClient.IsActive = false; CurrentAxis.updateCurrentE6Axis(); }
public OpenArms(string serverIP, int serverSocket, ref SharedMemorySpace globalCoordinates) { tunnelSystem = new ClientTunnel[10]; //initializeClients(serverIP, serverSocket); _globalCoordinates = globalCoordinates; _serverIp = serverIP; _serverSocket = serverSocket; CurrentAxis = new E6Axis(); CurrentPos = new E6Pos(); }
private void writerAssistant_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { writerAssistTimer.Restart(); BackgroundWorker worker = (BackgroundWorker)sender; E6Pos tempE6 = new OpenArms.E6Pos(); tempE6.updateE6Pos(calculateDelta()); ClientTunnel tempClient = getNextClient(); tempClient.writeVariable("MYPOS", tempE6.currentValue); tempClient.IsActive = false; WriterBackgroundTimer = writerAssistTimer.Elapsed.TotalMilliseconds; }
/// <summary> /// Removes the tunnel from the server and closes all connections. /// </summary> /// <param name="tunnel">The tunnel to be removed.</param> public virtual Task RemoveTunnelAsync(ClientTunnel tunnel) { return(RemoveTunnelAsync(tunnel, true)); }
/// <summary> /// Adds the tunnel. /// </summary> /// <param name="tunnel">The tunnel.</param> public virtual void AddTunnel(ClientTunnel tunnel) { Tunnels.TryAdd(tunnel.Id, tunnel); }