internal void Deactivated(ClientConnection activeConnection) { CallConnectionEventHandler(activeConnection, ClientConnectionEvent.INACTIVE); }
private void ServerAcceptThread() { running = true; DebugLog("Waiting for connections..."); while (running) { try { Socket newSocket = listeningSocket.Accept(); if (newSocket != null) { newSocket.NoDelay = true; DebugLog("New connection"); IPEndPoint ipEndPoint = (IPEndPoint)newSocket.RemoteEndPoint; DebugLog(" from IP: " + ipEndPoint.Address.ToString()); bool acceptConnection = true; if (OpenConnections >= maxOpenConnections) { acceptConnection = false; } if (acceptConnection && (connectionRequestHandler != null)) { acceptConnection = connectionRequestHandler(connectionRequestHandlerParameter, ipEndPoint.Address); } if (acceptConnection) { ClientConnection connection = null; if ((serverMode == ServerMode.SINGLE_REDUNDANCY_GROUP) || (serverMode == ServerMode.MULTIPLE_REDUNDANCY_GROUPS)) { RedundancyGroup catchAllGroup = null; RedundancyGroup matchingGroup = null; /* get matching redundancy group */ foreach (RedundancyGroup redGroup in redGroups) { if (redGroup.Matches(ipEndPoint.Address)) { matchingGroup = redGroup; break; } if (redGroup.IsCatchAll) { catchAllGroup = redGroup; } } if (matchingGroup == null) { matchingGroup = catchAllGroup; } if (matchingGroup != null) { connection = new ClientConnection(newSocket, securityInfo, apciParameters, alParameters, this, matchingGroup.asduQueue, debugOutput); matchingGroup.AddConnection(connection); DebugLog("Add connection to group " + matchingGroup.Name); } else { DebugLog("Found no matching redundancy group -> close connection"); newSocket.Close(); } } else { connection = new ClientConnection(newSocket, securityInfo, apciParameters, alParameters, this, new ASDUQueue(maxQueueSize, enqueueMode, alParameters, DebugLog), debugOutput); } if (connection != null) { allOpenConnections.Add(connection); CallConnectionEventHandler(connection, ClientConnectionEvent.OPENED); } } else { newSocket.Close(); } } } catch (Exception) { running = false; } } }
internal void AddConnection(ClientConnection connection) { connections.Add(connection); }
internal void RemoveConnection(ClientConnection connection) { connections.Remove(connection); }
private void ServerAcceptThread() { running = true; DebugLog("Waiting for connections..."); while (running) { try { Socket newSocket = listeningSocket.Accept(); if (newSocket != null) { newSocket.NoDelay = true; DebugLog("New connection"); IPEndPoint ipEndPoint = (IPEndPoint)newSocket.RemoteEndPoint; DebugLog(" from IP: " + ipEndPoint.Address.ToString()); bool acceptConnection = true; if (OpenConnections >= maxOpenConnections) { acceptConnection = false; } if (acceptConnection && (connectionRequestHandler != null)) { acceptConnection = connectionRequestHandler(connectionRequestHandlerParameter, ipEndPoint.Address); } if (acceptConnection) { ClientConnection connection; if (serverMode == ServerMode.SINGLE_REDUNDANCY_GROUP) { connection = new ClientConnection(newSocket, securityInfo, apciParameters, alParameters, this, asduQueue, debugOutput); } else { connection = new ClientConnection(newSocket, securityInfo, apciParameters, alParameters, this, new ASDUQueue(maxQueueSize, alParameters, DebugLog), debugOutput); } allOpenConnections.Add(connection); if (connectionEventHandler != null) { connectionEventHandler(connectionEventHandlerParameter, connection, ClientConnectionEvent.OPENED); } } else { newSocket.Close(); } } } catch (Exception) { running = false; } } }