/// <summary> /// creates a new SockIO object wrapping a socket /// connection to host:port, and its input and output streams /// </summary> /// <param name="pool">Pool this object is tied to</param> /// <param name="host">host to connect to</param> /// <param name="port">port to connect to</param> /// <param name="timeout">int ms to block on data for read</param> /// <param name="connectTimeout">timeout (in ms) for initial connection</param> /// <param name="noDelay">TCP NODELAY option?</param> public SockIO(SockIOPool pool, String host, int port, int timeout, int connectTimeout, bool noDelay) : this() { if (host == null || host.Length == 0) throw new ArgumentNullException(GetLocalizedString("host"), GetLocalizedString("null host")); _pool = pool; if (connectTimeout > 0) { _socket = GetSocket(host, port, connectTimeout); } else { _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _socket.Connect(new IPEndPoint(IPAddress.Parse(host), port)); } _networkStream = new BufferedStream(new NetworkStreamIgnoreSeek(_socket)); _host = host + ":" + port; }
public static SockIOPool GetInstance(String poolName) { if(Pools.ContainsKey(poolName)) return (SockIOPool)Pools[poolName]; SockIOPool pool = new SockIOPool(); Pools[poolName] = pool; return pool; }
public MaintenanceThread(SockIOPool pool) { _thread = new Thread(new ThreadStart(Maintain)); _pool = pool; }
/// <summary> /// creates a new SockIO object wrapping a socket /// connection to host:port, and its input and output streams /// </summary> /// <param name="pool">Pool this object is tied to</param> /// <param name="host">hostname:port</param> /// <param name="timeout">read timeout value for connected socket</param> /// <param name="connectTimeout">timeout for initial connections</param> /// <param name="noDelay">TCP NODELAY option?</param> public SockIO(SockIOPool pool, String host, int timeout, int connectTimeout, bool noDelay) : this() { if (host == null || host.Length == 0) throw new ArgumentNullException(GetLocalizedString("host"), GetLocalizedString("null host")); _pool = pool; String[] ip = host.Split(':'); // get socket: default is to use non-blocking connect if (connectTimeout > 0) { _socket = GetSocket(ip[0], int.Parse(ip[1], new System.Globalization.NumberFormatInfo()), connectTimeout); } else { _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _socket.Connect(new IPEndPoint(IPAddress.Parse(ip[0]), int.Parse(ip[1], new System.Globalization.NumberFormatInfo()))); } _networkStream = new BufferedStream(new NetworkStreamIgnoreSeek(_socket)); _host = host; }