How do you use UDP to communicate between computers?
Do you need to give information to your roscore that you can't transport with rosnodes?
Last updated
Was this helpful?
Do you need to give information to your roscore that you can't transport with rosnodes?
Last updated
Was this helpful?
Was this helpful?
import socket
host = <enter host IP here>
port = 5000
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind(('', port))
s.listen(1)
c, addr = s.accept()
print("CONNECTION FROM:", str(addr))
c.send(b"HELLO, How are you ? Welcome to Akash hacking World")
msg = "Bye.............."
c.send(msg.encode())
c.close()
import socket
host = <Same IP>
port = 5000
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', port))
msg = s.recv(1024)
while msg:
print('Received:' + msg.decode())
msg = s.recv(1024)
s.close()#!/usr/bin/env python
import os
from socket import *
import rospy
from std_msgs.msg import String
from nav_msgs.msg import Odometry
# Because of transformations
import tf_conversions
import tf2_ros
import geometry_msgs.msg
import math
from geometry_msgs.msg import PoseWithCovarianceStamped
from tf.transformations import euler_from_quaternion, quaternion_from_euler
rospy.init_node("sender")
#100.71.173.127
#100.74.41.103
host = "100.71.173.127" # set to IP address of target computer
port = 13000
addr = (host, port)
UDPSock = socket(AF_INET, SOCK_DGRAM)
roll = 0.0
pitch = 0.0
yaw = 0.0
def get_rotation (msg):
if msg is not None:
global roll, pitch, yaw
orientation_q = msg.pose.pose.orientation
orientation_list = [orientation_q.x, orientation_q.y, orientation_q.z, orientation_q.w]
(roll, pitch, yaw) = euler_from_quaternion (orientation_list)
print('X =',msg.pose.pose.position.x, 'Y =',msg.pose.pose.position.y, 'Yaw =',math.degrees(yaw))
mess=str(msg.pose.pose.position.x)+" "+str(msg.pose.pose.position.y)
data = bytes(str(mess), 'utf-8')
UDPSock.sendto(data, addr)
sub = rospy.Subscriber ('/amcl_pose', PoseWithCovarianceStamped, get_rotation) # geometry_msgs/PoseWithCovariance pose
while not rospy.is_shutdown():
hi = "r"#!/usr/bin/env python
import os
from socket import *
import rospy
from std_msgs.msg import String
from nav_msgs.msg import Odometry
import json
from std_msgs.msg import Float64MultiArray
rospy.init_node("receiver")
mypub = rospy.Publisher('/other_odom', Float64MultiArray,queue_size = 10)
host = "100.74.41.103"
port = 13000
buf = 1024
addr = (host, port)
UDPSock = socket(AF_INET, SOCK_DGRAM)
UDPSock.bind(addr)
while not rospy.is_shutdown():
(data, addr) = UDPSock.recvfrom(buf)
data=data.decode('utf-8')
data=data.split()
x=data[0]
y=data[1]
x=float(x)
y=float(y)
my_msg = Float64MultiArray()
d=[x, y, 67.654236]
my_msg.data = d
mypub.publish(my_msg)
if data == "exit":
break
UDPSock.close()
os._exit(0)