Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Connection to 127.0.0.1:10000 failed - System.Net.Sockets.SocketException: Connection refused

Discussion in 'Robotics' started by GerenMeric, May 15, 2023.

  1. GerenMeric

    GerenMeric

    Joined:
    May 15, 2023
    Posts:
    47
    Hello there,

    I am trying to subscribe messages published from ROS into Unity. I am using a PC with Ubuntu 18.04. I have ROS Melodic and Unity 2021.3.23f1 installed. Also, ROS TCP Endpoint git cloned (without any versioning or git checkout) then, built into my catkin workspace and ROS TCP Connector installed into Unity using package manager via GIT URL (both ROS TCP Endpoint and Connector is 0.7.0). I have implemented both publisher (on ROS side with Python) and subscriber (Unity side with C#) then, prepared my Unity scene. First, i have through ROS Settings at the 'robotics' tab, have set ROS IP address to 127.0.0.1 and kept ROS Port as 10000. Then, added two empty game objects. After that, added ROSConnection script included in ROS Connection package as component of one of these empty game objects and subscriber as component of the other one. I didn't forget to set ROS IP Address to 127.0.0.1 and Port to 10000 under ROS Connection (Script) field. Later on, i wanted to test it. Through terminal i have entered the command: 'roscore' and opened a new tab at that terminal then, ran the publisher there. After that, when i pressed that play button to run the Unity side i have encountered this error looping on my Unity console: "
    Connection to 127.0.0.1:10000 failed - System.Net.Sockets.SocketException (0x80004005): Connection refused
    at System.Net.Sockets.TcpClient.Connect (System.String hostname, System.Int32 port) [0x0019d] in <d46c5ae75c754461a9c54e6fc90c0279>:0
    "

    That's the log if i am not mistaken:

    "
    Connection to 127.0.0.1:10000 failed - System.Net.Sockets.SocketException (0x80004005): Connection refused
    at System.Net.Sockets.TcpClient.Connect (System.String hostname, System.Int32 port) [0x0019d] in <d46c5ae75c754461a9c54e6fc90c0279>:0
    at Unity.Robotics.ROSTCPConnector.ROSConnection.ConnectionThread (System.String rosIPAddress, System.Int32 rosPort, System.Single networkTimeoutSeconds, System.Single keepaliveTime, System.Int32 sleepMilliseconds, System.Action`1[T] OnConnectionStartedCallback, System.Action DeregisterAll, Unity.Robotics.ROSTCPConnector.ROSConnection+OutgoingMessageQueue outgoingQueue, System.Collections.Concurrent.ConcurrentQueue`1[T] incomingQueue, System.Threading.CancellationToken token) [0x000b2] in /home/baran/liveFeedToVR/Library/PackageCache/com.unity.robotics.ros-tcp-connector@c27f00c6cf/Runtime/TcpConnector/ROSConnection.cs:790
    UnityEngine.Debug:Log (object)
    Unity.Robotics.ROSTCPConnector.ROSConnection/<ConnectionThread>d__115:MoveNext () (at Library/PackageCache/com.unity.robotics.ros-tcp-connector@c27f00c6cf/Runtime/TcpConnector/ROSConnection.cs:854)
    System.Threading._ThreadPoolWaitCallback:performWaitCallback ()
    "

    These are my ROS parameters:

    ROS_IP: 127.0.0.1

    ROS_MASTER_URI: http://127.0.0.1:10000

    ROS_HOSTNAME: 127.0.0.1

    *** Note: ****

    If i open another terminal and enter: "roslaunch ros_tcp_endpoint endpoint.launch" before i press the play button in Unity, i can see the icon in front of ROS_IP is blue, i can get messages into Unity as i want and don't get any errors. But, unfortunately i don't have such an option for my case. Since, i need to get Unity side to connect to ROS at the start without any terminal or prompt. Just as it should have when using ROSConnection script.

    Thanks in advance all the support you have offered.
     
  2. ActiveSim

    ActiveSim

    Joined:
    May 10, 2019
    Posts:
    59
    Hi GerenMeric,

    I think I do not get your question. You need to start the "ROS-Unity-bridge" in the terminal. It isn't possible to establish a connection without it. If you want to do this automatically, you can start the terminal from a scipt in your Unity project.

    Does this help or can you describe again what isn't working in your case and why?
     
    GerenMeric likes this.
  3. GerenMeric

    GerenMeric

    Joined:
    May 15, 2023
    Posts:
    47
    Thank you so much for your kind help. Please correct me if i am wrong. But, as far as i understand from your reply, i have to input the command:
    roslaunch ros_tcp_endpoint enpoint.launch
    into bash terminal before running my application in Unity. Otherwise, it's impossible for Unity to connect to ROS.
     
  4. jabrail_chumakov

    jabrail_chumakov

    Joined:
    Feb 17, 2020
    Posts:
    18
    If I understand correctly, you're looking for a way to run your ROS program with a single script, including the ROS-TCP endpoint. To achieve this, you can add the necessary information to your .launch file in the package folder you're using.

    However, if you're aiming to run everything, including the ROS side, directly from Unity by pressing the Play button, it's not possible because the ROS endpoint needs to be opened first. One possible workaround is to use Unity for Linux. In this case, you may be able to load the ROS-TCP endpoint launch file immediately after pressing the Play button, but you'll need to try it out to see if it works.
     
    GerenMeric likes this.
  5. GerenMeric

    GerenMeric

    Joined:
    May 15, 2023
    Posts:
    47
    Thank you so much for replying and for the explaination.