跳到正文

Socket向服务端发送数据(Python)

Python 1437 次浏览
Socket向服务端发送数据(Python)
import socket
def soct(str_r):
    try:
        address = ('ip', 端口)
        client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        client.connect(address) 
        client.sendall(kk.encode()) #发送数据
        client.settimeout(10) #设置超时时间
        client.close()
    except Exception as e:
        return "失败  "+str(e)

评论

加载中…