/// <summary> /// Create a communications client /// </summary> /// <remarks> /// Note that typical connection string should be prefixed with a "protocol=tcp", "protocol=udp", "protocol=serial" or "protocol=file" /// </remarks> public static IClient Create(string connectionString) { Dictionary<string, string> connectionData = connectionString.ParseKeyValuePairs(); IClient client = null; string protocol; if (connectionData.TryGetValue("protocol", out protocol)) { connectionData.Remove("protocol"); StringBuilder settings = new StringBuilder(); foreach (string key in connectionData.Keys) { settings.Append(key); settings.Append("="); settings.Append(connectionData[key]); settings.Append(";"); } switch (protocol.ToLower()) { case "tcp": client = new TcpClient(settings.ToString()); break; case "udp": client = new UdpClient(settings.ToString()); break; case "file": client = new FileClient(settings.ToString()); break; case "serial": client = new SerialClient(settings.ToString()); break; default: throw new ArgumentException(protocol + " is not a valid transport protocol."); } } else { throw new ArgumentException("Transport protocol must be specified."); } return client; }
/// <summary> /// Creates an instance of RADIUS client for sending request to a RADIUS server. /// </summary> /// <param name="serverName">Name or address of the RADIUS server.</param> /// <param name="serverPort">Port number of the RADIUS server.</param> /// <param name="sharedSecret">Shared secret used for encryption and authentication.</param> /// <remarks></remarks> public RadiusClient(string serverName, int serverPort, string sharedSecret) { this.SharedSecret = sharedSecret; this.RequestAttempts = 1; this.ReponseTimeout = 15000; this.NewPinModeMessage1 = DefaultNewPinModeMessage1; this.NewPinModeMessage2 = DefaultNewPinModeMessage2; this.NewPinModeMessage3 = DefaultNewPinModeMessage3; this.NextTokenModeMessage = DefaultNextTokenModeMessage; m_udpClient = new UdpClient(string.Format("Server={0}; RemotePort={1}; LocalPort=0", serverName, serverPort)); m_udpClient.ReceivedData += new System.EventHandler`1[[PCS.GenericEventArgs`1[[PCS.IdentifiableItem`2[[Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], PCS.Core, Version=3.0.116.286, Culture=neutral, PublicKeyToken=null]], PCS.Core, Version=3.0.116.286, Culture=neutral, PublicKeyToken=null]](m_udpClient_ReceivedData);