internal void PushReverseListen(Guid deviceID, Guid agentSock, IPEndPoint agentDirect) { base.CheckDisposed(); var device = _principal.SingleOrDefault(t => t.ID == deviceID); if (device == null || device.ListenState.AgentSock != Guid.Empty) { throw new InvalidOperationException("PushReverseListen"); } device.ListenState.AgentSock = agentSock; device.ListenState.AgentDirect = agentDirect; device.WaitHandle.Set(); App.LogInfo("PushReverseListen {0} {1}", agentSock, agentDirect); }
public object this[string key] { get { object result = null; lock (m_CachedList.SyncRoot) { var item = m_CachedList.SingleOrDefault(i => i.Key == key); if (item != null) { result = item.Value; } } return(result); } }
//------------------------------------------------------------- private async Task <bool> ClientSendData(byte[] data, string IP, IPAddress player) //------------------------------------------------------------- { Log.Get().Write("Communication client sending to: " + IP + ", size: " + data.Length); if (player == null) { player = playerList.SingleOrDefault(p => p.ToString().Equals(IP)); } try { communicationClient = new TcpClient(); await communicationClient.ConnectAsync(IP, COMMUNICATION_PORT); var stream = communicationClient.GetStream(); //Send data size byte[] dataSize = BitConverter.GetBytes(data.Length); if (dataSize.Length != sizeof(int)) { Log.Get().Write("Int wrong size", Log.LogType.Error); } await stream.WriteAsync(dataSize, 0, dataSize.Length); //Send data await stream.WriteAsync(data, 0, data.Length); stream.Close(); communicationClient.Close(); return(true); } catch (SocketException ex) { if (ex.SocketErrorCode.Equals("ConnectionRefused") || ex.SocketErrorCode.Equals("TimedOut")) { Log.Get().Write("Communication client Socketexception (Player disconnected or firewall?) size:" + data.Length + " ip:" + IP + " ex:" + ex, Log.LogType.Warning); } else { Log.Get().Write("Communication client Socketexception (Firewall problem) size:" + data.Length + " ip:" + IP + " ex:" + ex, Log.LogType.Error); } Log.Get().Write("Removing " + player?.ToString() + " client from list", Log.LogType.Warning); if (player != null) { playerList.Remove(player); //Failed to send to client, remove from list //Update gui kobberLanGui.Invoke(new Action(() => { kobberLanGui.UpdatePlayersAmount(playerList); })); } return(false); } catch (Exception ex) { Log.Get().Write("Removing " + player?.ToString() + " client from list", Log.LogType.Warning); if (player != null) { playerList.Remove(player); //Failed to send to client, remove from list //Update gui kobberLanGui.Invoke(new Action(() => { kobberLanGui.UpdatePlayersAmount(playerList); })); } Log.Get().Write("Communication client exception: " + ex, Log.LogType.Error); return(false); } }