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

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 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 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 failed - System.Net.Sockets.SocketException (0x80004005): Connection refused
at System.Net.Sockets.TcpClient.Connect (System.String hostname, System.Int32 port) [0x0019d] in :0

That's the log if i am not mistaken:

Connection to failed - System.Net.Sockets.SocketException (0x80004005): Connection refused
at System.Net.Sockets.TcpClient.Connect (System.String hostname, System.Int32 port) [0x0019d] in :0
at Unity.Robotics.ROSTCPConnector.ROSConnection.ConnectionThread (System.String rosIPAddress, System.Int32 rosPort, System.Single networkTimeoutSeconds, System.Single keepaliveTime, System.Int32 sleepMilliseconds, System.Action1[T] OnConnectionStartedCallback, System.Action DeregisterAll, Unity.Robotics.ROSTCPConnector.ROSConnection+OutgoingMessageQueue outgoingQueue, System.Collections.Concurrent.ConcurrentQueue1[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/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:




*** 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.

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?

1 Like

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.

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.

1 Like

Thank you so much for replying and for the explaination.

Where can I disable this message? I do not need it's functionality and it's spamming the console