internal SocketClientConnection(SocketClientSettings config) { configuration = config; responseHelper = new ServerResponseHelper(config); clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); ConnectToServer(); }
public static ISocketClientConnection GetConnection(SocketClientSettings settings) { if (settings == null) { throw new InvalidOperationException("Settings cannot be null"); } return(new SocketClientConnection(settings)); }
/// <summary> /// Defines a global, static configuration for any future connections needed by this client /// </summary> /// <param name="server">Server network address</param> /// <param name="port">Server port</param> /// <param name="encoding">Server encoding</param> /// <param name="packetSize">Packet/buffer size. The SAME size used on the server must be defined</param> /// <param name="maxAttempts">Maximum connection attempts</param> /// <param name="receiveTimeOut">Maximum waiting time (in milliseconds) for receiving request data</param> /// <param name="serializerSettings">Maximum waiting time (in milliseconds) for receiving request data</param> public static void Configure(string server, int port, Encoding encoding, int packetSize = 1024 * 100, int maxAttempts = 10, int receiveTimeOut = 0, JsonSerializerSettings serializerSettings = null) { staticConf = new SocketClientSettings( server, port, encoding, packetSize, maxAttempts, receiveTimeOut, serializerSettings); }
public static SocketClientSettings GetConfiguration() { if (staticConf == null) { return(null); } SocketClientSettings conf = new SocketClientSettings(); foreach (PropertyInfo prop in conf.GetType().GetProperties()) { try { var value = staticConf.GetType().GetProperty(prop.Name).GetValue(staticConf); if (value == null) { continue; } prop.SetValue(conf, value); } catch { } } return(conf); }
public ServerResponseHelper(SocketClientSettings config) { configuration = config; }
public static void SetDefaultSettings(SocketClientSettings settings) { defaultSettings = settings; }