赞
踩
用socket发送Float64MultiArray的数据,写完以后运行服务器和客户端,报错BrokenPipeError: [Errno 32] Broken pipe
网上搜了一下解决办法,这一篇说的是一般是客户端和服务端未建立好链接,但其实命令行有正常打印connect的提示
再次检查了一下客户端和服务器端的代码,
将客户端的代码改正确,readdress = ('192.168.103.xx', 12345) #客户client IP guest IP
改为readdress = ('192.168.103.5', 12345) #客户client IP guest IP
192.168.103.5这个IP确认是客户端IP
address = ('192.168.103.13', 12345) #server IP local IP
readdress = ('192.168.103.5', 12345) #客户client IP guest IP
其次就是看客户端的报错:
neousys@neousys-Nuvo-5000:~/wqw/Myproject$ python tcp_dual_client.py
Traceback (most recent call last):
File "tcp_dual_client.py", line 87, in <module>
pub.publish(buf_msg)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/topics.py", line 879, in publish
data = args_kwds_to_message(self.data_class, args, kwds)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/msg.py", line 122, in args_kwds_to_message
return data_class(*args)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/std_msgs/msg/_Float64MultiArray.py", line 74, in __init__
super(Float64MultiArray, self).__init__(*args, **kwds)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/genpy/message.py", line 344, in __init__
raise TypeError('Invalid number of arguments, args should be %s' % str(self.__slots__) + ' args are' + str(args))
TypeError: Invalid number of arguments, args should be ['layout', 'data'] args are(u'[146.0, 137.0, 129.0, 128.0, 136.0, 80.0, 2.0]',)
这里报错的是 pub.publish(buf_msg)
这个buf_msg数据格式不对,Invalid number of arguments, publish的数据格式应该是 [‘layout’, ‘data’],检查了一下代码发现应该发的是vision_pose,而不是buf_msg。vision_pose才是Float64MultiArray格式的数据,将下面代码pub.publish(buf_msg)
改为pub.publish(vision_pose)
就OK了
if __name__ == '__main__': s = socket.socket() IP = "192.168.103.13" port = 12345 s.connect((IP, port)) vision_pose = Float64MultiArray() #gesture_flag = s.recv(1024).decode() rospy.init_node('tcp_dual_server', anonymous=True) pub = rospy.Publisher('dual_msg_send', Float64MultiArray, queue_size=10) #gesture_flag = s.recv(1024).decode() #rospy.init_node('talker', anonymous=True) rate = rospy.Rate(50) # 10hz while not rospy.is_shutdown(): # for data in s.recv(1024): # sting_msg = data.decode() buf_msg = s.recv(1024).decode() vision_pose = json.loads(buf_msg) pub.publish(buf_msg) print(vision_pose) rate.sleep() #rospy.spin()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。