pip install socket
pip install websocket
pip install websocket-client
socket
import socket
Address = ('127.0.0.1', 3000) # Socket服務器地址,根據自己情況修改
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(Address) # 嘗試連接服務端
msg="test"
s.sendall(msg.encode())
websocket
from websocket import create_connection
import json
url = 'ws://127.0.0.1:3000'
data = '{}'
ws = create_connection(url)
msg=["Send",{"content":"test"},1]
ws.send(json.dumps(msg))