From 95fb6e36ff5e65e459dca4eceeec3f61b544d748 Mon Sep 17 00:00:00 2001 From: Sinan Date: Fri, 28 Sep 2018 12:22:27 +0200 Subject: [PATCH 3/5] Improve tcp connection establishment --- rsb-cil-test/Program.cs | 2 +- rsb-cil/Rsb/Transport/Socket/BusClientConnection.cs | 12 ++++++------ 2 files changed, 7 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..f991dec 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,13 @@ 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 endPoint; private TcpClient client = null; private NetworkStream stream = null; - public BusClientConnection(String host, int port) + public BusClientConnection(byte[] ip, int port) { - this.host = host; - this.port = port; + endPoint = new IPEndPoint(new IPAddress(ip), port); } public void Activate() @@ -33,7 +32,8 @@ namespace Rsb.Transport.Socket LOGGER.Debug("Activating"); - this.client = new TcpClient(host, port); + this.client = new TcpClient(); + this.client.Connect(endPoint); this.client.NoDelay = true; this.stream = client.GetStream(); -- 2.14.2.windows.1