public SocketClient CreateClient(IPEndPoint localep, IPEndPoint remoteep, bool bbeginread, SocketCreator creator) { //Creates the Socket for sending data over TCP. Socket s = null; if (remoteep.Address.AddressFamily != AddressFamily.InterNetworkV6) { s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); } else { s = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp); } // Connects to the host using IPEndPoint. try { LogMessage(MessageImportance.Highest, "EXCEPTION", string.Format("Attempting to create TCP connection from {0} to {1}", localep, remoteep)); s.Bind(localep); s.Connect(remoteep); } catch (SocketException e) { LogError(MessageImportance.Highest, "CreateClient", string.Format("Exception calling Bind or Connect, Winsock Native: {0}, Socket: {1}\n{2}", e.NativeErrorCode, e.SocketErrorCode, e)); return(null); } if (!s.Connected) { LogError(MessageImportance.Highest, "Connection", "Failed to connect to " + remoteep); return(null); } SocketClient client = creator.CreateSocket(s, this); if (bbeginread) { client.DoAsyncRead(); } return(client); }
public SocketClient CreateClient(IPEndPoint ep, bool bbeginread, SocketCreator creator, bool IsIPV6) { //Creates the Socket for sending data over TCP. Socket s = null; if (IsIPV6 == false) { s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); } else { s = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp); } // Connects to the host using IPEndPoint. try { s.Connect(ep); } catch (SocketException e) { LogError(MessageImportance.Highest, "CreateClient", string.Format("Exception calling Connect, Winsock Native: {0}, Socket: {1}\n{2}", e.NativeErrorCode, e.SocketErrorCode, e)); return(null); } if (!s.Connected) { LogError(MessageImportance.Highest, "Connection", "Failed to connect to " + ep.Address.ToString() + " port " + ep.Port); return(null); } SocketClient client = creator.CreateSocket(s, this); if (bbeginread) { client.DoAsyncRead(); } return(client); }
public SocketClient CreateClient(IPEndPoint localep, IPEndPoint remoteep, bool bbeginread, SocketCreator creator) { //Creates the Socket for sending data over TCP. Socket s = null; if (remoteep.Address.AddressFamily != AddressFamily.InterNetworkV6) s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); else s = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp); // Connects to the host using IPEndPoint. try { LogMessage(MessageImportance.Highest, "EXCEPTION", string.Format("Attempting to create TCP connection from {0} to {1}", localep, remoteep)); s.Bind(localep); s.Connect(remoteep); } catch (SocketException e) { LogError(MessageImportance.Highest, "CreateClient", string.Format("Exception calling Bind or Connect, Winsock Native: {0}, Socket: {1}\n{2}", e.NativeErrorCode, e.SocketErrorCode, e)); return null; } if (!s.Connected) { LogError(MessageImportance.Highest, "Connection", "Failed to connect to " + remoteep); return null; } SocketClient client = creator.CreateSocket(s, this); if (bbeginread) client.DoAsyncRead(); return client; }
public SocketClient CreateClient(IPEndPoint ep, bool bbeginread, SocketCreator creator, bool IsIPV6) { //Creates the Socket for sending data over TCP. Socket s = null; if (IsIPV6 == false) s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); else s = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp); // Connects to the host using IPEndPoint. try { s.Connect(ep); } catch (SocketException e) { LogError(MessageImportance.Highest, "CreateClient", string.Format("Exception calling Connect, Winsock Native: {0}, Socket: {1}\n{2}", e.NativeErrorCode, e.SocketErrorCode, e)); return null; } if (!s.Connected) { LogError(MessageImportance.Highest, "Connection", "Failed to connect to " + ep.Address.ToString() + " port " + ep.Port); return null; } SocketClient client = creator.CreateSocket(s, this); if (bbeginread) client.DoAsyncRead(); return client; }