【问题标题】:Where does websocket for python store it's received datapython的websocket在哪里存储它接收到的数据
【发布时间】:2023-03-24 18:45:02
【问题描述】:

所以我正在编写一个信使,我希望代码对某些消息做出反应,但为此我需要我的代码来查看接收到的数据。 (我在 Windows 上编码): 一切正常,但我不知道接收到的数据存储在哪里,或者您是否必须添加一些东西。

最好的办法是存储它的列表。

def get(s, new_window=None):
    while True:
        tm = s.recv(1024)
        print("\nReceived: ",tm.decode('ascii'))
        A.append(tm.decode('ascii'))
        if A == "RickRoll":
            print("Success")
        print("Enter: ")
        if tm == "RickRoll":
            print("It works")

def set_(s):
    while True:
        i=input("Enter : ")
        s.send(i.encode('ascii'))

serversocket = socket.socket()
host = socket.gethostname()
port = 9981
serversocket.bind((host,port))
serversocket.listen(1)
clientsocket,addr = serversocket.accept()
t1=threading.Thread( target = get ,  args = (clientsocket,) )
t1.start()
t2=threading.Thread( target = set_ ,  args = (clientsocket,) )
t2.start()

我是否必须添加类似的代码

A.append(tm.decode('ascii'))
        if A == "RickRoll":
            print("Success")
        print("Enter: ")
        if tm == "RickRoll":
            print("It works")

有没有办法做到这一点。上面的解决方法不行

【问题讨论】:

    标签: python-3.x websocket


    【解决方案1】:

    为此,您需要使用 tm 变量:

    tm = s.recv(1024)
    

    我建议将 tm 附加到自制变量,然后使用它

    【讨论】:

      猜你喜欢
      • 2014-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-09
      • 1970-01-01
      相关资源
      最近更新 更多