internal ServiceServerLink <M, T> CreateServiceServerLink <M, T>(string service, bool persistent, string request_md5sum, string response_md5sum, IDictionary <string, string> header_values) where M : RosMessage, new() where T : RosMessage, new() { lock ( shuttingDownMutex ) { if (shuttingDown) { return(null); } } int serv_port = -1; string serv_host = ""; if (!LookupService(service, ref serv_host, ref serv_port)) { return(null); } TcpTransport transport = new TcpTransport(pollManager.poll_set); if (transport.connect(serv_host, serv_port)) { Connection connection = new Connection(); connectionManager.AddConnection(connection); ServiceServerLink <M, T> client = new ServiceServerLink <M, T>(service, persistent, request_md5sum, response_md5sum, header_values); lock (serviceServerLinksMutex) serviceServerLinks.Add(client); connection.initialize(transport, false, null); client.initialize(connection); return(client); } return(null); }
private void onRetryTimer(object o) { ROS.Debug()($"[{ThisNode.Name}] TransportPublisherLink: onRetryTimer"); if (dropping) { return; } if (needs_retry && DateTime.UtcNow.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.connectedHost; int port = old_transport.connectedPort; TcpTransport transport = new TcpTransport(); if (transport.connect(host, port)) { Connection conn = new Connection(); conn.initialize(transport, false, null); initialize(conn); ConnectionManager.Instance.AddConnection(conn); } } }
public static bool exists(string serviceName, bool logFailureReason = false) { string mappedName = Names.Resolve(serviceName); string host = ""; int port = 0; if (ServiceManager.Instance.LookUpService(mappedName, ref host, ref port)) { var transport = new TcpTransport(); if (transport.connect(host, port)) { var m = new Dictionary <string, string> { { "probe", "1" }, { "md5sum", "*" }, { "callerid", ThisNode.Name }, { "service", mappedName } }; var h = new Header(); h.Write(m, out byte[] headerbuf, out int size); byte[] sizebuf = BitConverter.GetBytes(size); transport.write(sizebuf, 0, sizebuf.Length); transport.write(headerbuf, 0, size); return(true); } if (logFailureReason) { ROS.Info()($"[{ThisNode.Name}] waitForService: Service[{mappedName}] could not connect to host [{host}:{port}], waiting..."); } } else if (logFailureReason) { ROS.Info()($"[{ThisNode.Name}] waitForService: Service[{mappedName}] has not been advertised, waiting..."); } return(false); }
private void PendingConnectionDone(PendingConnection conn, Task <XmlRpcCallResult> callTask) { lock ( pendingConnections ) { pendingConnections.Remove(conn); } if (callTask.IsFaulted) { List <string> errorMessages = new List <string>(); foreach (Exception exception in callTask.Exception.InnerExceptions) { errorMessages.Add(BuildExceptionMessages(exception)); } ROS.Warn()($"[{ThisNode.Name}] Negotiating for {name} has failed (Error: {string.Join( ", ", errorMessages.ToArray() )})."); return; } if (!callTask.Result.Success) { ROS.Warn()($"[{ThisNode.Name}] Negotiating for {name} has failed. XML-RPC call failed."); return; } var resultValue = callTask.Result.Value; lock ( shutdown_mutex ) { if (shutting_down || _dropped) { return; } } var proto = new XmlRpcValue(); if (!XmlRpcManager.Instance.ValidateXmlRpcResponse("requestTopic", resultValue, proto)) { ROS.Warn()($"[{ThisNode.Name}] Negotiating for {name} has failed."); return; } string peerHost = conn.Client.Host; int peerPort = conn.Client.Port; string xmlrpcUri = $"http://{peerHost}:{peerPort}/"; if (proto.Count == 0) { ROS.Debug()($"[{ThisNode.Name}] Could not agree on any common protocols with [{xmlrpcUri}] for topic [{name}]"); return; } if (proto.Type != XmlRpcType.Array) { ROS.Warn()($"[{ThisNode.Name}] Available protocol info returned from {xmlrpcUri} is not a list."); return; } string protoName = proto[0].GetString(); if (protoName == "UDPROS") { ROS.Error()($"[{ThisNode.Name}] UDP is currently not supported. Use TCPROS instead."); } else if (protoName == "TCPROS") { if (proto.Count != 3 || proto[1].Type != XmlRpcType.String || proto[2].Type != XmlRpcType.Int) { ROS.Warn()($"[{ThisNode.Name}] TcpRos Publisher should implement string, int as parameter"); return; } string pubHost = proto[1].GetString(); int pubPort = proto[2].GetInt(); ROS.Debug()($"[{ThisNode.Name}] Connecting via tcpros to topic [{name}] at host [{pubHost}:{pubPort}]"); var transport = new TcpTransport(PollManager.Instance.poll_set) { _topic = name }; if (transport.connect(pubHost, pubPort)) { var connection = new Connection(); var pubLink = new TransportPublisherLink(this, xmlrpcUri); connection.initialize(transport, false, null); pubLink.initialize(connection); ConnectionManager.Instance.AddConnection(connection); lock ( publisher_links_mutex ) { addPublisherLink(pubLink); } ROS.Debug()($"[{ThisNode.Name}] Connected to publisher of topic [{name}] at [{pubHost}:{pubPort}]"); } else { ROS.Error()($"[{ThisNode.Name}] Failed to connect to publisher of topic [{name}] at [{pubHost}:{pubPort}]"); } } else { ROS.Error()($"[{ThisNode.Name}] The XmlRpc Server does not provide a supported protocol."); } }