using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net.Sockets; using System.Net; namespace sharpknife { class SocketClient { protected Socket GetSocket() { Socket tc = null; IPHostEntry hostEntry = null; hostEntry = this.GetHostEntry("gmail.com"); if (hostEntry != null) { foreach (IPAddress address in hostEntry.AddressList) { tc = this.TryGetSocket(address, 993); if (tc != null) { break; } } } return tc; } private Socket TryGetSocket(IPAddress address, int port) { IPEndPoint ipe = new IPEndPoint(address, port); Socket tc = null; try { tc = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp); tc.Connect(ipe); if (tc.Connected == true) { tc.ReceiveTimeout = 3600; tc.SendBufferSize = 18000; tc.ReceiveBufferSize = 18000; } } catch { tc = null; } return tc; } private IPHostEntry GetHostEntry(string serverName) { try { return Dns.GetHostEntry(serverName); } catch { } return null; } } }