Hi,
Im trying to get a websocket connection to a echo server working, it seems i can connect fine, but then my message never goes out
from gi.repository import Soup
from gi.repository import GLib
TEST_URL = 'wss://echo.websocket.org'
print(Soup.get_major_version(),
Soup.get_minor_version(),
Soup.get_micro_version())
def connect():
session = Soup.Session()
session.add_feature(Soup.Logger.new(Soup.LoggerLogLevel.BODY, -1))
message = Soup.Message.new('GET', TEST_URL)
message.connect('network-event', print)
message.connect('starting', print)
session.websocket_connect_async(message,
None,
None,
None,
_on_connect,
None)
def _on_connect(session, result, user_data):
con = session.websocket_connect_finish(result)
con.connect('message', _on_message)
con.connect('closed', _on_closed)
con.connect('closing', _on_closing)
con.connect('error', _on_error)
con.connect('pong', _on_pong)
print('Trying to send message')
con.send_text('test')
def _on_message(websocket_connection, type, message):
print('MESSAGE')
bytes_ = message.get_data()
string = bytes_.decode()
print(string)
def _on_error(websocket_connection, error):
print('ERROR')
print(error)
def _on_closed(websocket_connection):
print('CLOSED')
def _on_closing(websocket_connection):
print('CLOSING')
def _on_pong(websocket_connection, message):
print('Pong')
bytes_ = message.get_data()
string = bytes_.decode()
print(string)
connect()
GLib.MainLoop().run()
my logging output looks like this
User:~/projects/tests$ python3 websocket.py
websocket.py:1: PyGIWarning: Soup was imported without specifying a version first. Use gi.require_version('Soup', '2.4') before import to ensure that the right version gets loaded.
from gi.repository import Soup
2 68 2
<Soup.Message object at 0x7f597e4e7d20 (SoupMessage at 0x23d28a0)> <enum G_SOCKET_CLIENT_RESOLVING of type Gio.SocketClientEvent> None
<Soup.Message object at 0x7f597e4e7d20 (SoupMessage at 0x23d28a0)> <enum G_SOCKET_CLIENT_RESOLVED of type Gio.SocketClientEvent> None
<Soup.Message object at 0x7f597e4e7d20 (SoupMessage at 0x23d28a0)> <enum G_SOCKET_CLIENT_CONNECTING of type Gio.SocketClientEvent> <Gio.TcpConnection object at 0x7f597a34aaf0 (GTcpConnection at 0x2712860)>
<Soup.Message object at 0x7f597e4e7d20 (SoupMessage at 0x23d28a0)> <enum G_SOCKET_CLIENT_RESOLVING of type Gio.SocketClientEvent> None
<Soup.Message object at 0x7f597e4e7d20 (SoupMessage at 0x23d28a0)> <enum G_SOCKET_CLIENT_CONNECTED of type Gio.SocketClientEvent> <Gio.TcpConnection object at 0x7f597a34aaf0 (GTcpConnection at 0x2712860)>
<Soup.Message object at 0x7f597e4e7d20 (SoupMessage at 0x23d28a0)> <enum G_SOCKET_CLIENT_TLS_HANDSHAKING of type Gio.SocketClientEvent> <__gi__.GTlsClientConnectionGnutls object at 0x7f597a3520a0 (GTlsClientConnectionGnutls at 0x27202e0)>
<Soup.Message object at 0x7f597e4e7d20 (SoupMessage at 0x23d28a0)> <enum G_SOCKET_CLIENT_TLS_HANDSHAKED of type Gio.SocketClientEvent> <__gi__.GTlsClientConnectionGnutls object at 0x7f597a3520a0 (GTlsClientConnectionGnutls at 0x27202e0)>
<Soup.Message object at 0x7f597e4e7d20 (SoupMessage at 0x23d28a0)> <enum G_SOCKET_CLIENT_COMPLETE of type Gio.SocketClientEvent> <__gi__.GTlsClientConnectionGnutls object at 0x7f597a3520a0 (GTlsClientConnectionGnutls at 0x27202e0)>
<Soup.Message object at 0x7f597e4e7d20 (SoupMessage at 0x23d28a0)>
> GET HTTP/1.1
> Soup-Debug-Timestamp: 1577787514
> Soup-Debug: SoupSession 1 (0x23c1100), SoupMessage 1 (0x23d28a0), SoupSocket 1 (0x27120e0)
> Host: echo.websocket.org
> Upgrade: websocket
> Connection: Upgrade
> Sec-WebSocket-Key: awpDu/YRflST/3IGgpzCIA==
> Sec-WebSocket-Version: 13
> Accept-Encoding: gzip, deflate
< HTTP/1.1 101 Web Socket Protocol Handshake
< Soup-Debug-Timestamp: 1577787515
< Soup-Debug: SoupMessage 1 (0x23d28a0)
< Connection: Upgrade
< Date: Tue, 31 Dec 2019 10:14:47 GMT
< Sec-WebSocket-Accept: T5QWZRI+y69Zn5tLZZnUj2rO2Vg=
< Server: Kaazing Gateway
< Upgrade: websocket
Trying to send message