connect() public method

public connect ( string host, int port ) : bool
host string
port int
return bool
Beispiel #1
0
        private void onRetryTimer(object o)
        {
#if DEBUG
            EDB.WriteLine("TransportPublisherLink: onRetryTimer");
#endif
            if (dropping)
            {
                return;
            }
            if (needs_retry && DateTime.Now.Subtract(next_retry).TotalMilliseconds < 0)
            {
                retry_period =
                    TimeSpan.FromSeconds((retry_period.TotalSeconds > 20) ? 20 : (2 * retry_period.TotalSeconds));
                needs_retry = false;
                TcpTransport old_transport = connection.transport;
                string       host          = old_transport.connected_host;
                int          port          = old_transport.connected_port;

                TcpTransport transport = new TcpTransport();
                if (transport.connect(host, port))
                {
                    Connection conn = new Connection();
                    conn.initialize(transport, false, null);
                    initialize(conn);
                    ConnectionManager.Instance.addConnection(conn);
                }
            }
        }
Beispiel #2
0
        internal ServiceServerLink <S> createServiceServerLink <S>(string service, bool persistent, string request_md5sum, string response_md5sum, IDictionary header_values)
            where S : IRosService, new()
        {
            lock (shutting_down_mutex)
            {
                if (shutting_down)
                {
                    return(null);
                }
            }

            int    serv_port = -1;
            string serv_host = "";

            if (!lookupService(service, ref serv_host, ref serv_port))
            {
                return(null);
            }
            TcpTransport transport = new TcpTransport(poll_manager.poll_set);

            if (transport.connect(serv_host, serv_port))
            {
                Connection connection = new Connection();
                connection_manager.addConnection(connection);
                ServiceServerLink <S> client = new ServiceServerLink <S>(service, persistent, request_md5sum, response_md5sum, header_values);
                lock (service_server_links_mutex)
                    service_server_links.Add(client);
                connection.initialize(transport, false, null);
                client.initialize(connection);
                return(client);
            }
            return(null);
        }
Beispiel #3
0
        public static bool exists(string service_name, bool print_failure_reason)
        {
            string mapped_name = names.resolve(service_name);

            string host = "";
            int port = 0;

            if (ServiceManager.Instance.lookUpService(mapped_name, ref host, ref port))
            {
                TcpTransport transport = new TcpTransport();

                IDictionary m = new Hashtable
                {
                    {"probe", "1"},
                    {"md5sum", "*"},
                    {"callerid", this_node.Name},
                    {"service", mapped_name}
                };

                byte[] headerbuf = null;
                int size = 0;
                Header h = new Header();
                h.Write(m, ref headerbuf, ref size);

                if (transport.connect(host, port))
                {
                    byte[] sizebuf = BitConverter.GetBytes(size);

                    transport.write(sizebuf, 0, sizebuf.Length);
                    transport.write(headerbuf, 0, size);

                    return true;
                }
                if (print_failure_reason)
                {
                    ROS.Info("waitForService: Service[{0}] could not connect to host [{1}:{2}], waiting...", mapped_name, host, port);
                }
            }
            else if (print_failure_reason)
            {
                ROS.Info("waitForService: Service[{0}] has not been advertised, waiting...", mapped_name);
            }
            return false;
        }
Beispiel #4
0
        public static bool exists(string service_name, bool print_failure_reason)
        {
            string mapped_name = names.resolve(service_name);

            string host = "";
            int    port = 0;

            if (ServiceManager.Instance.lookUpService(mapped_name, ref host, ref port))
            {
                TcpTransport transport = new TcpTransport();

                IDictionary m = new Hashtable
                {
                    { "probe", "1" },
                    { "md5sum", "*" },
                    { "callerid", this_node.Name },
                    { "service", mapped_name }
                };

                byte[] headerbuf = null;
                int    size      = 0;
                Header h         = new Header();
                h.Write(m, ref headerbuf, ref size);

                if (transport.connect(host, port))
                {
                    byte[] sizebuf = BitConverter.GetBytes(size);

                    transport.write(sizebuf, 0, sizebuf.Length);
                    transport.write(headerbuf, 0, size);

                    return(true);
                }
                if (print_failure_reason)
                {
                    ROS.Info("waitForService: Service[{0}] could not connect to host [{1}:{2}], waiting...", mapped_name, host, port);
                }
            }
            else if (print_failure_reason)
            {
                ROS.Info("waitForService: Service[{0}] has not been advertised, waiting...", mapped_name);
            }
            return(false);
        }
Beispiel #5
0
        public void pendingConnectionDone(PendingConnection conn, IntPtr res)
        {
            XmlRpcValue result = XmlRpcValue.LookUp(res);

            lock (shutdown_mutex)
            {
                if (shutting_down || _dropped)
                {
                    return;
                }
            }
            XmlRpcValue proto = new XmlRpcValue();

            if (!XmlRpcManager.Instance.validateXmlrpcResponse("requestTopic", result, ref proto))
            {
                conn.failures++;
                EDB.WriteLine("Negotiating for " + conn.parent.name + " has failed " + conn.failures + " times");
                return;
            }
            lock (pending_connections_mutex)
            {
                pending_connections.Remove(conn);
            }
            string peer_host  = conn.client.Host;
            int    peer_port  = conn.client.Port;
            string xmlrpc_uri = "http://" + peer_host + ":" + peer_port + "/";

            if (proto.Size == 0)
            {
#if DEBUG
                EDB.WriteLine("Couldn't agree on any common protocols with [" + xmlrpc_uri + "] for topic [" + name +
                              "]");
#endif
                return;
            }
            if (proto.Type != TypeEnum.TypeArray)
            {
                EDB.WriteLine("Available protocol info returned from " + xmlrpc_uri + " is not a list.");
                return;
            }
            string proto_name = proto[0].Get <string>();
            if (proto_name == "UDPROS")
            {
                EDB.WriteLine("OWNED! Only tcpros is supported right now.");
            }
            else if (proto_name == "TCPROS")
            {
                if (proto.Size != 3 || proto[1].Type != TypeEnum.TypeString || proto[2].Type != TypeEnum.TypeInt)
                {
                    EDB.WriteLine("publisher implements TCPROS... BADLY! parameters aren't string,int");
                    return;
                }
                string pub_host = proto[1].Get <string>();
                int    pub_port = proto[2].Get <int>();
#if DEBUG
                EDB.WriteLine("Connecting via tcpros to topic [" + name + "] at host [" + pub_host + ":" + pub_port +
                              "]");
#endif

                TcpTransport transport = new TcpTransport(PollManager.Instance.poll_set)
                {
                    _topic = name
                };
                if (transport.connect(pub_host, pub_port))
                {
                    Connection             connection = new Connection();
                    TransportPublisherLink pub_link   = new TransportPublisherLink(this, xmlrpc_uri);

                    connection.initialize(transport, false, null);
                    pub_link.initialize(connection);

                    ConnectionManager.Instance.addConnection(connection);

                    lock (publisher_links_mutex)
                    {
                        addPublisherLink(pub_link);
                    }


#if DEBUG
                    EDB.WriteLine("Connected to publisher of topic [" + name + "] at  [" + pub_host + ":" + pub_port +
                                  "]");
#endif
                }
                else
                {
                    EDB.WriteLine("Failed to connect to publisher of topic [" + name + "] at  [" + pub_host + ":" +
                                  pub_port + "]");
                }
            }
            else
            {
                EDB.WriteLine("Your xmlrpc server be talking jibber jabber, foo");
            }
        }