/// <summary> /// Hammers the server with connections. /// </summary> private static void ConnectionHammer(int index) { Random rand = new Random(index); for (int i = 0; i < connectionsPerHammer; i++) { bool tcpSelected = false; if (TCPServerEndPointsKeys.Count > 0 && UDPServerEndPointsKeys.Count > 0) { tcpSelected = (rand.NextDouble() > 0.5); } else if (TCPServerEndPointsKeys.Count > 0) { tcpSelected = true; } //options.Options.Add("ReceiveConfirmationRequired", ""); IPEndPoint selectedEndPoint; ConnectionInfo connInfo; if (tcpSelected) { selectedEndPoint = TCPServerEndPointsKeys[(int)(TCPServerEndPoints.Count * rand.NextDouble())]; connInfo = new ConnectionInfo(selectedEndPoint, TCPServerEndPoints[selectedEndPoint]); } else { selectedEndPoint = UDPServerEndPointsKeys[(int)(UDPServerEndPoints.Count * rand.NextDouble())]; connInfo = new ConnectionInfo(selectedEndPoint, UDPServerEndPoints[selectedEndPoint]); } try { Connection conn; if (tcpSelected) { conn = TCPConnection.GetConnection(connInfo, sendReceiveOptions); conn.SendObject(packetTypeStr, clientHammerData); if (closeConnectionAfterSend) { conn.CloseConnection(false); } } else { conn = UDPConnection.GetConnection(connInfo, UDPConnection.DefaultUDPOptions, sendReceiveOptions); conn.SendObject(packetTypeStr, clientHammerData); if (closeConnectionAfterSend) { conn.CloseConnection(false); } //SendReceiveOptions unmanagedOptions = new SendReceiveOptions<NullSerializer>(); //UDPConnection.SendObject("Unmanaged", clientHammerData, connInfo.RemoteEndPoint, unmanagedOptions, connInfo.ApplicationLayerProtocol); } } catch (CommsException ex) { Interlocked.Increment(ref exceptionCount); LogTools.AppendStringToLogFile("ClientExceptions", ex.ToString()); } } }