SpecialistOff.NET / Вопросы / Статьи / Фрагменты кода / Резюме / Метки / Помощь / Файлы

Список вопросов Печать

Как подключиться к websocket?


Метки: websocket 

Ответы

RemiZOffAlex  Создано: 2023-03-20 18:04:37.050281  Обновлено: 2023-03-20 18:11:20.074105
pip3 install websocket-client

HTTP

#!/usr/bin/env python3

import websocket


ws = websocket.WebSocket()
ws.connect("ws://localhost:8080/websocket")

print "Sending 'Hello, World'..."
ws.send("Hello, World")
print "Sent"

print "Receiving..."
result = ws.recv()
print "Received '%s'" % result

ws.close()

HTTPS

#!/usr/bin/env python3

import websocket


ws = websocket.WebSocket()
ws.connect("wss://specialistoff.net:443/ws")

print "Sending 'Hello, World'..."
ws.send("Hello, World")
print "Sent"

print "Receiving..."
result = ws.recv()
print "Received '%s'" % result

ws.close()

Возможно будут интересны и другие вопросы