def wsproto_demo(host, port):
<EOL>print('<STR_LIT>'.format(host, port))<EOL>conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<EOL>conn.connect((host, port))<EOL>print('<STR_LIT>')<EOL>ws = WSConnection(ConnectionType.CLIENT)<EOL>net_send(ws.send(Request(host=host, target='<STR_LIT>')), conn)<EOL>net_recv(ws, conn)<EOL>events = ws.events()<EOL>event = next(events)<EOL>if isinstance(event, AcceptConnection):<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>message = "<STR_LIT>"<EOL>print('<STR_LIT>'.format(message))<EOL>net_send(ws.send(Message(data=message)), conn)<EOL>net_recv(ws, conn)<EOL>event = next(events)<EOL>if isinstance(event, TextMessage):<EOL><INDENT>print('<STR_LIT>'.format(event.data))<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>payload = b"<STR_LIT>"<EOL>print('<STR_LIT>'.format(payload))<EOL>net_send(ws.send(Ping(payload=payload)), conn)<EOL>net_recv(ws, conn)<EOL>event = next(events)<EOL>if isinstance(event, Pong):<EOL><INDENT>print('<STR_LIT>'.format(event.payload))<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>print('<STR_LIT>')<EOL>net_send(ws.send(CloseConnection(code=<NUM_LIT:1000>, reason='<STR_LIT>')), conn)<EOL>net_recv(ws, conn)<EOL>conn.shutdown(socket.SHUT_WR)<EOL>net_recv(ws, conn)<EOL>
Demonstrate wsproto:

0) Open TCP connection
1) Negotiate WebSocket opening handshake
2) Send a message and display response
3) Send ping and display pong
4) Negotiate WebSocket closing handshake

:param stream: a socket stream