ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Multiple TCP connections using rosserial_server with WiFi Arduino

asked 2017-10-26 04:50:06 -0500

Andy West gravatar image

updated 2017-10-26 14:30:31 -0500

Dear all,

I am currently running an Arduino Uno* with an ATWINC1500 WiFi breakout from Adafruit and can successfully publish topics over WiFi to a master using rosrun rosserial_python tcp. This has been achieved using code modified from this previous ROS answer supplied by @ahendrix.

The trouble I run into is running two of these devices at the same time. They both have unique IP addresses and are connected to the network, running differently named topics, and individually can be successfully connected and publish topics.

The first device can be connected using rosrun rosserial_python tcp. Simply starting a second device does not lead to be being connected. If I run a second with a different node name to avoid conflicts (by using rosrun rosserial_python tcp __name:=OtherNodeName), I get an error "socket.error: [Errno 98] Address already in use".

As the socket can't be given as an argument to, I tried using rosrun rosserial_server socket_node as rosserial_server in theory can handle multiple connections. Using default port 11411, I find the node displays:

Listening for rosserial TCP connection on port 11411 but never finds any devices, unlike rosserial_python which was successful.

Am I missing something for rosserial_server to be able to identify and connect to these devices?

Is there another way of connecting multiple TCP devices such as these arduinos with wifi simultaneously?

Thank you for your time,



Having followed some very good advice from gvdhoorn, I investigated the packet traffic using Wireshark. Turns out for rosserial_server socket_node the connection between the arduino and the master must not complete (there are a few messages back and forth, but finishes before the "normal" regular published traffic commences as seen when using rosserial_python tcp).

By adding a short delay after nh.advertise(), the master and the arduino are able to make a connection (though socket_node reports some errors to begin with), and start publishing. This also allows for multiple arduinos to be connected! However, the connection then drops out after a minute or so from what I observe as TCP out-of-order issues.

I thought this might be because of the delay(1000) in the main loop, so I replaced this instead for using millis() and letting nh.spinonce() not get held up. This didn't improve the situation, it in fact might have made the drop out occur earlier, but I haven't done any actual timings to confirm that.

There are occurrences of TCP out-of-order when using, but they seem to resolve themselves very quickly and not terminate the connection between the arduino and the master when using identical code. I left this running for a few hours with no termination of connection.

Better questions:

What is it about socket_node that leads to traffic being treated differently compared to and lead to the connection being terminated?

What could be done to improve the stability of TCP connections when using rosserial_server socket_node ... (more)

edit retag flag offensive close merge delete


I'm not a rosserial expert, but just to get a feeling for what is going on at the network level, I'd run Wireshark while trying to get things to connect. That should at least tell you whether your clients are trying to connect, how, where and in what way. It should also show server activity.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-26 05:08:48 -0500 )edit

Note that using TCP/IP over a wireless link is not a very good choice for anything interactive. Whenever I used rosserial over wireless I've used the UDP variant. Trouble is though that it currently lacks some of the functionality that the TCP implementation does have.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-26 05:09:56 -0500 )edit

I've investigated using Wireshark. For rosserial_python it appears to run nicely, however for rosserial_server socket_node there are some errors being thrown around. By adding delay(100); just after nh.advertise(); the arduinos manage to connect! But dropout randomly later.

Andy West gravatar image Andy West  ( 2017-10-26 08:53:04 -0500 )edit

The "socket.error: [Errno 98] Address already in use" suggest that both copies of are trying to listen on the same port number. I'm not sure if a single node is designed to handle multiple clients or not, you might want to look for documentation about this.

ahendrix gravatar image ahendrix  ( 2017-10-27 21:45:07 -0500 )edit

If a single node is supposed to handle multiple clients, then this behavior is a bug. Otherwise you may want to try running the second node and its Arduino on a different port number.

ahendrix gravatar image ahendrix  ( 2017-10-27 21:46:36 -0500 )edit

(Failing to handle multiple clients is still probably a bug for most software that has a listening socket, but if the docs don't say it's supported you may have a hard time getting this "bug" fixed unless you're willing to submit the fix yourself)

ahendrix gravatar image ahendrix  ( 2017-10-27 21:47:08 -0500 )edit

Hello dear community. I need your help. I am facing problems with rosserial_server socket_node. can you please take a look to my post? Thank you so much RosSerial_Server

subarashi gravatar image subarashi  ( 2020-09-14 09:57:21 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-10-31 08:56:25 -0500

Andy West gravatar image

The result of this investigation is that it may have been an intermittent bug. Having reinstalled rosserial_server just to be pedantic in checking everything, the continual dropping out of devices using rosserial_server socket.launch has be greatly reduced (drop out ~ 1 per hour compared to ~1 per minute).

The rosserial_server socket_node will accept multiple clients successfully as it should (unlike as ahendrix points out).

The only advice I can offer to others is to include a reconnect function as mentioned in the question. As rosserial_server is in development, if I can track down where this bug might of occurred, I will report it.

Thank you all for your help.

edit flag offensive delete link more



I don't know how much this applies to your problem but I use multiple rosserial_server nodes instead (one for each client) by adding args="_port:=11412", etc. to the .launch file.

prnthp gravatar image prnthp  ( 2017-11-05 14:08:02 -0500 )edit

That's a useful tip! Never though of setting separate ports to allow for separate nodes when using rosserial_server. Thanks prnthp.

Andy West gravatar image Andy West  ( 2017-11-05 14:34:17 -0500 )edit

can you guys elaborate how to do this port modification? can i make the port number arguments changable and connect to several ports like that? please guide

ELLEO gravatar image ELLEO  ( 2018-02-22 20:05:02 -0500 )edit

Question Tools



Asked: 2017-10-26 04:50:06 -0500

Seen: 3,719 times

Last updated: Oct 31 '17