简体   繁体   English

Matlab 服务器与树莓派上的 python 客户端 BrokenPipeError: [Errno 32] Broken pipe

[英]Matlab Server with python client on raspberry pi BrokenPipeError: [Errno 32] Broken pipe

I am trying to gather data from sensors connected to a raspberry pi and send them over to my laptop for some processing.我正在尝试从连接到树莓派的传感器收集数据并将它们发送到我的笔记本电脑进行一些处理。 I have written a very basic matlab server (for on my laptop)我写了一个非常基本的 matlab 服务器(用于我的笔记本电脑)

t = tcpip('127.0.0.1', 42069, 'NetworkRole', 'server');
fopen(t);

flag = true;
while flag
        if t.BytesAvailable > 0
            t.BytesAvailable
            raw_data = fread(t, t.BytesAvailable);
            data = typecast(uint8(raw_data), 'double');
            current_x = data(1);
            current_y = a.cell_size*a.rows - data(2);
            current_th = -data(3);
            flag = false;
        end
end
.
.
.
fclose(t)

On my PI I have written the following class to handle sending the data over.在我的 PI 上,我编写了以下 class 来处理发送数据。

class LocalizationClient():

    #TCP_IP = '127.0.0.1'
    TCP_IP = '192.168.1.5'
    TCP_PORT = 42069
    BUFFER_SIZE = 1000
    # MESSAGE = "Hello, World!"
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    def __init__(self):
        self.s.connect((self.TCP_IP, self.TCP_PORT))
        print("connected to server")


    def sendData(self,MESSAGE):
        try:
            self.s.send(MESSAGE)
        except BrokenPipeError as e:
            print(e)
            self.close()
            raise RuntimeError()

In my driver code I create an object and try to send a message like so:在我的驱动程序代码中,我创建了一个 object 并尝试发送如下消息:

lo_c = lc.LocalizationClient()
lo_c.sendData(np.array([float(x), float(y), float(th)]))
.
.
.
for x in range(50):

    measures = lidar.measures
    measures = np.append([float(dx), float(dy), float(dth)], measures)

    lo_c.sendData(measures)
    time.sleep(.2)


All of this was working fine and dandy while I was just testing with loopback on my laptop, but when I tried to put it on the pi I get the following error on the python client side:当我只是在笔记本电脑上使用环回进行测试时,所有这些都工作得很好而且很漂亮,但是当我试图把它放在 pi 上时,我在 python 客户端收到以下错误:

connected to server [Errno 32] Broken pipe连接到服务器 [Errno 32] 损坏 pipe

Traceback (most recent call last):
  File "/home/pi/Desktop/EXAMPLES/LocalizationClient.py", line 21, in sendData
    self.s.send(MESSAGE)
BrokenPipeError: [Errno 32] Broken pipe

It seems that connecting still works but when I try to send to the server the client throws an error.似乎连接仍然有效,但是当我尝试发送到服务器时,客户端会引发错误。 The server seems fine and Im not trying to send any data back over to the client yet.服务器似乎很好,我还没有尝试将任何数据发送回客户端。 I have been banging my head into this one for a while now and any help would be appreciated.一段时间以来,我一直在努力解决这个问题,我们将不胜感激。

ps some details about the network setup if it helps, I have put the pi in ad-hoc mode with IP statically assigned as 192.168.1.1 and connected my macbook to the network it created.如果有帮助,请附上有关网络设置的一些详细信息,我已将 pi 置于 ad-hoc 模式,IP 静态分配为 192.168.1.1,并将我的 macbook 连接到它创建的网络。 My Mac is assigned static IP 192.168.1.5.我的 Mac 分配了 static IP 192.168.1.5。

So I figured out the issue.所以我想通了这个问题。 While I could see the port was open the way the matlab TCPIP object works is that it will silently refuse any connection that does not come from the IP passed into the constructor.虽然我可以看到端口以 matlab TCPIP object 的工作方式打开,但它会默默地拒绝任何不是来自 IP 传递给构造函数的连接。 So I was able to construct the object which would listen for a connection on the port.所以我能够构建 object 来监听端口上的连接。 On the python side my client would see this "connect" but really the server was refusing the connection causing broken pipe.在 python 端,我的客户端会看到这个“连接”,但实际上服务器拒绝连接导致 pipe 损坏。 (this is also why it was working fine on local host but not remote) (这也是它在本地主机上运行良好但在远程主机上运行良好的原因)

Fix is easy just change:修复很容易,只需更改:

t = tcpip('127.0.0.1', 42069, 'NetworkRole', 'server');
fopen(t);

to:至:

t = tcpip('0.0.0.0', 42069, 'NetworkRole', 'server');
fopen(t);

This will allow matlab server to accept a connection from any ip on LAN on specified port.这将允许 matlab 服务器接受来自 LAN 上指定端口上的任何 ip 的连接。 Alternatively one could supply matlab server with clients IP to only accept connections from the one device but if IP is not static then it might change on you.或者,可以为 matlab 服务器和客户端 IP 提供仅接受来自一个设备的连接,但如果 IP 不是 ZA81259C56FBCZDF1DEF458E959C297ZE 可能会改变你。 Also is important to disable firewalls on devices.禁用设备上的防火墙也很重要。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 已解决:Python 多处理 imap BrokenPipeError: [Errno 32] Broken pipe pdftoppm - Solved: Python multiprocessing imap BrokenPipeError: [Errno 32] Broken pipe pdftoppm 我得到 BrokenPipeError: [Errno 32] Broken pipe 错误 python - I get BrokenPipeError: [Errno 32] Broken pipe error in python BrokenPipeError:[Errno 32] makefile 插座的 pipe 损坏? - BrokenPipeError: [Errno 32] Broken pipe for makefile socket? TCP 服务器/客户端:[Errno 32] 损坏 pipe - TCP Server/Client: [Errno 32] Broken pipe BrokenPipeError: [Errno 32] 运行 GAN 时管道损坏错误 - BrokenPipeError: [Errno 32] Broken pipe error when running GANs 为什么我不断收到 [BrokenPipeError: [Errno 32] Broken pipe],无论我的池中有多少工作人员在 python3.8 中使用多处理库? - Why do I keep getting [BrokenPipeError: [Errno 32] Broken pipe] no matter the number of workers in my Pool with multiprocessing lib in python3.8? 带有Java客户端的python套接字服务器-socket.error:[Errno 32]管道损坏 - python socket server with java client - socket.error: [Errno 32] Broken pipe BrokenPipeError:[Errno 32] Python 多处理 - BrokenPipeError: [Errno 32] Python Multiprocessing conn.send('Hi'.encode()) BrokenPipeError: [Errno 32] Broken pipe (SOCKET) - conn.send('Hi'.encode()) BrokenPipeError: [Errno 32] Broken pipe (SOCKET) 获取 BrokenPipeError:[Errno 32] 发送第二个套接字 MSG 时损坏 pipe - Getting BrokenPipeError: [Errno 32] Broken pipe When Sending Second Socket MSG
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM