public virtual void testParseSocketAddressToHostIp() { string localhostName; IPAddress localIP; try { var inetAddress = IPAddress.Loopback; localhostName = Dns.GetHostName(); IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName()); // `Dns.Resolve()` method is deprecated. localIP = ipHostInfo.AddressList[0]; if (null == localIP) { return; } } catch (UnknownHostException) { localhostName = "localhost"; localIP = IPAddress.Parse("127.0.0.1"); } IPEndPoint socketAddress = new IPEndPoint(IPAddress.Parse(localhostName), port); string res = RemotingUtil.parseSocketAddressToHostIp(socketAddress); Assert.Equal(localIP, res); }
public virtual void testParseSocketAddressToString() { string localhostName; string localIP; try { InetAddress inetAddress = InetAddress.LocalHost; localhostName = inetAddress.HostName; localIP = inetAddress.HostAddress; if (null == localIP || string.IsNullOrWhiteSpace(localIP)) { return; } } catch (UnknownHostException) { localhostName = "localhost"; localIP = "127.0.0.1"; } IPEndPoint socketAddress = new IPEndPoint(localhostName, port); string res = RemotingUtil.parseSocketAddressToString(socketAddress); Assert.Equal(localIP + ":" + port, res); }
public virtual void testParseSocketAddressToString_MuiltiFormatTest() { IPEndPoint socketAddress = new IPEndPoint(IPAddress.Parse("/127.0.0.1"), 1111); string res = RemotingUtil.parseSocketAddressToString(socketAddress); Assert.Equal("127.0.0.1:1111", res); socketAddress = new InetSocketAddress("sofatest-2.stack.alipay.net/127.0.0.1", 12200); res = RemotingUtil.parseSocketAddressToString(socketAddress); Assert.Equal("127.0.0.1:12200", res); }
/// <summary>Method that connects to the Adept ACE server and gets all the available controllers and robots</summary> /// <author>Damian Jimenez</author> /// <param name="remotingHost">URL on which the Adept ACE server is hosted on.</param> /// <param name="remotingPort">Port on which the Adept ACE server is listening on.</param> /// <param name="remotingName">Name of the Adept ACE server (typically just "ace").</param> /// <param name="callbackPort">Callback port for the Adept ACE server.</param> /// <returns><c>ObservableCollection<string>[]</c> an array of length 2 containing the controllers and robots that were found. Index 0 is the controllers and index 1 is the robots.</returns> public ObservableCollection <string>[] ConnectToServer(string remotingHost, int remotingPort, string remotingName, int callbackPort) { bool noMatches = true; try { controllers.Clear(); robots.Clear(); // Set up the server to allow remote connections and connect to the ACE server RemotingUtil.InitializeRemotingSubsystem(true, callbackPort); ace = (IAceServer)RemotingUtil.GetRemoteServerObject(typeof(IAceServer), remotingName, remotingHost, remotingPort); // We don't use WriteOutput, because that method definition isn't available to this class and it isn't required for things to work. Console.WriteLine($"Connecting to the Adept ACE server ({remotingName}) on:\n\t{remotingHost}:{remotingPort}\n"); // Print out all the controllers that are found and available Console.Write($"Controllers found:"); foreach (IAdeptController controller in ace.Root.Filter(new ObjectTypeFilter(typeof(IAdeptController)), true)) { // We don't use WriteOutput, because that method definition isn't available to this class and it isn't required for things to work. Console.WriteLine($"\n\t{controller.FullPath}"); controllers.Add(controller.FullPath); noMatches = false; } if (noMatches) { Console.WriteLine($"\n\tNone"); } Console.Write($"\n"); // Print out all the robots that are found connected to the workspace and available Console.Write($"Robots found:"); foreach (IAdeptRobot robot in ace.Root.Filter(new ObjectTypeFilter(typeof(IAdeptRobot)), true)) { // We don't use WriteOutput, because that method definition isn't available to this class and it isn't required for things to work. Console.WriteLine($"\n\t{robot.FullPath}"); robots.Add(robot.FullPath); noMatches = false; } if (noMatches) { Console.WriteLine($"\n\tNone"); } Console.Write($"\n"); } catch (Exception e) { Console.WriteLine($"Unable to connect to the Adept ACE server properly.\nERROR: {e.Message}\n"); } ObservableCollection <string>[] res = { controllers, robots }; return(res); }
public virtual void testParseRemoteHostIp() { Connection conn; try { parser.initUrlArgs(connAddress); conn = client.getConnection(connAddress, 1000); IChannel channel = conn.Channel; string res = RemotingUtil.parseRemoteIP(channel); Assert.Equal(localIP, res); } catch (System.Exception) { Assert.False(true); } }