#!/usr/bin/env python
import rospy
from std_msgs.msg import String
name = "sender"
pub_topic = "long_string"
rospy.init_node(name, anonymous=True)
pub = rospy.Publisher(pub_topic, String, queue_size=1)
hello_str = String()
rate = rospy.Rate(1)
pub_size = 10000000 #1M byte
# pub_size = 50000000 #5M byte
# pub_size = 100000000 #10M byte
# pub_size = 200000000 #20M byte
# pub_size = 500000000 #50M byte
my_string = ""
for i in range(pub_size):
my_string += "#"
while not rospy.is_shutdown():
hello_str.data = my_string + ":" + str(rospy.get_time())
pub.publish(hello_str)
# rospy.loginfo(str(hello_str.data).split(":")[1])
rate.sleep()
#!/usr/bin/env python
import rospy
from std_msgs.msg import String
name = "receiver"
sub_topic = "long_string"
def callback(data):
current_time = str(rospy.get_time())
arrival_data = str(data.data).split(":")
time_diff = float(current_time) - float(arrival_data[1])
string_size = len(arrival_data[0])
rospy.loginfo(str(string_size) + "byte: "+str(time_diff) + "second")
rospy.loginfo("speed: " + str(float(string_size)/time_diff) + "byte/s")
rospy.init_node(name, anonymous=True)
rospy.loginfo("Init")
rospy.Subscriber(sub_topic, String, callback)
rospy.spin()
<launch>
<node pkg="msg_send" type="sender_speed.py" name="sender"/>
<node pkg="msg_send" type="receiver_speed.py" name="receiver" output="screen"/>
</launch>
$ roslaunch msg_send sr_speed.launch
실행이 안된다ㅠㅠ용량이 크고 느려져서 그런것 같다...아마도...?