From 733dbc9892a057a060da561de7e00846ad3b6898 Mon Sep 17 00:00:00 2001 From: Sinan Date: Fri, 28 Sep 2018 12:22:27 +0200 Subject: [PATCH 2/4] Improve tcp connection establishment All DNS resolves in BusClientConnection are removed, since they are really slow. Now they are two constructors. One which is easy to use by directly inserting the ip and port of the remote host. One is with an IPEndPoint, thus the user can create an Endpoint with resolved dns host. The advantage is, that the same Endpoint can be used, which saves much time. --- rsb-cil-test/Program.cs | 2 +- rsb-cil/Rsb/Transport/Socket/BusClientConnection.cs | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/rsb-cil-test/Program.cs b/rsb-cil-test/Program.cs index 16eeed1..1c5f39d 100644 --- a/rsb-cil-test/Program.cs +++ b/rsb-cil-test/Program.cs @@ -12,7 +12,7 @@ namespace rsbciltest { class MainClass { - static readonly string host = "localhost"; + static readonly byte[] host = new byte[] { 127, 0, 0, 1}; static readonly int port = 30010; public static void PrintEvent(Event theEvent) diff --git a/rsb-cil/Rsb/Transport/Socket/BusClientConnection.cs b/rsb-cil/Rsb/Transport/Socket/BusClientConnection.cs index 87eddbe..e9a9f55 100644 --- a/rsb-cil/Rsb/Transport/Socket/BusClientConnection.cs +++ b/rsb-cil/Rsb/Transport/Socket/BusClientConnection.cs @@ -6,6 +6,7 @@ using System.IO; using Google.Protobuf; using Rsb.Protocol; +using System.Net; namespace Rsb.Transport.Socket { @@ -17,15 +18,19 @@ namespace Rsb.Transport.Socket private static readonly int MESSAGE_LENGTH_SIZE = 4; private static readonly int MESSAGE_VERSION_SIZE = 4; - private String host; - private int port; + private IPEndPoint remoteEndPoint; private TcpClient client = null; private NetworkStream stream = null; - public BusClientConnection(String host, int port) + // legacy + public BusClientConnection(byte[] ip, int port) { - this.host = host; - this.port = port; + remoteEndPoint = new IPEndPoint(new IPAddress(ip), port); + } + + public BusClientConnection(IPEndPoint remote) + { + remoteEndPoint = remote; } public void Activate() @@ -33,7 +38,8 @@ namespace Rsb.Transport.Socket LOGGER.Debug("Activating"); - this.client = new TcpClient(host, port); + this.client = new TcpClient(remoteEndPoint.AddressFamily); + this.client.Connect(remoteEndPoint); this.client.NoDelay = true; this.stream = client.GetStream(); -- 2.14.2.windows.1