客户端服务器python

时间:2019-04-08 06:03:19

标签: python-3.x fpga

我已经按照以下方式连接了GUI(计算机)-FPGA-PLC。 FPGA在这里用作GUI的服务器和PLC的客户端。 GUI和PLC的数据是通过使用TCP / IP协议的中介者(即使用Python编程的FPGA)通过FPGA发送和接收的。

我在同一页中编写的客户服务器代码。

sboard.listen()      #(Fpga in listening mode)
while True:
    print('waiting for connection')
    connboard, addrboard = sboard.accept()
    print('connecting to {} port {}'.format(*plcserver_address))

    splc.connect(plcserver_address)    #(Fpga conects with plc as a client)

    print('Connected by', addrboard)
    try:
        while True:
            datagui = connboard.recv(1024) #data received form gui tofpga
            if datagui:
                print('received data from gui{!r}'.format(datagui))
                splc.sendall(datagui) #data send from fpga to plc
                print('data send')
                dataplc = splc.recv(1024)
                print('received data from plc{!r}'.format(dataplc))
                connboard.sendall(dataplc)
                print('finally data is send back to gui')
            else:
                splc.close()
                print('no data from gui')
                break
    finally:
        splc.close()
        sboard.close()
        print('connection lost')

首先尝试平稳运行,但是在关闭gui的连接并尝试再次与fpga连接后,它给出了错误消息:

OSError                                   Traceback (most recent call last)
<ipython-input-11-7e789770a359> in <module>()
     13 while True:
     14     print('waiting for connection')
---> 15     connboard, addrboard = sboard.accept()
     16     print('connecting to {} port {}'.format(*plcserver_address))
     17     splc.connect(plcserver_address)

/usr/lib/python3.6/socket.py in accept(self)
    203         For IP sockets, the address info is a pair (hostaddr, port).
    204         """
--> 205         fd, addr = self._accept()
    206         # If our type has the SOCK_NONBLOCK flag, we shouldn't pass it onto the
    207         # new socket. We do not currently allow passing SOCK_NONBLOCK to

OSError: [Errno 9] Bad file descriptor

0 个答案:

没有答案