ROS Kinetic: Data receive via socket Python3

asked 2019-08-11 03:38:09 -0500

MartaWisniewska gravatar image

updated 2019-08-11 22:35:59 -0500

ahendrix gravatar image

Hi, I'm in the process of using python and ROS so my question seems trivial.

I want to receive data from another computer using UDP (Ethernet). When I want to run "rosrun" an error appears.

**^CTraceback (most recent call last):

    File " /home/getac/catkin_ws/src/autopilot/scripts/", line 15, in <module>
        data = sock.recvfrom(1024)


How can I improve "rosrun" to work?


#!/usr/bin/env python
# - *- coding: utf- 8 - *-
import rospy

import socket

IP = '' # IP komputera

IP_as_bytes = bytes(map(int, IP.split('.')))

PORT = 3113

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

sock.bind(('', PORT))

while True:

    data = sock.recvfrom(1024)
    print("Message:", data)
edit retag flag offensive close merge delete


It looks like your program works until you stop it with Ctrl-C . It also seems like it would behave the same way without ROS.

ahendrix gravatar image ahendrix  ( 2019-08-11 22:43:00 -0500 )edit

I'd add that the sock.recvfrom(X) call appears to be blocking execution until it receives some data. But for whatever reason it isn't receiving anything.

This isn't a ROS question, you're only using python socket. StackOverflow would be a better forum.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2019-08-12 03:28:55 -0500 )edit
GPrathap gravatar image GPrathap  ( 2021-04-13 04:39:24 -0500 )edit