ROS Kinetic: Data receive via socket Python3

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

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/autopilot_socket.py", line 15, in <module>
        data = sock.recvfrom(1024)

KeyboardInterrupt

How can I improve "rosrun" to work?

My autopilot_socket.py:

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

import socket

IP = '192.168.88.103' # 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

Comments

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 imageahendrix ( 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 imagePeteBlackerThe3rd ( 2019-08-12 03:28:55 -0500 )edit