python 在python中通过套接字接收消息

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 在python中通过套接字接收消息相关的知识,希望对你有一定的参考价值。

import time

import socket               # Import socket module

s = socket.socket()         # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345                # Reserve a port for your service.

s.connect((host, port))
while True:
    data = s.recv(1024)
    if  data:
        print(data)
    time.sleep(0.1)

s.close()                    # Close the socket when done


exit(0)

以上是关于python 在python中通过套接字接收消息的主要内容,如果未能解决你的问题,请参考以下文章