ROS Kinetic: Data receive via socket Python3
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)
Asked by MartaWisniewska on 2019-08-11 03:38:09 UTC
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.
Asked by ahendrix on 2019-08-11 22:43:00 UTC
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.
Asked by PeteBlackerThe3rd on 2019-08-12 03:28:55 UTC
Maybe this helps https://stackoverflow.com/questions/60863258/python-socket-tcp-communication-with-subprocess-on-ros
Asked by GPrathap on 2021-04-13 04:39:24 UTC