Files
itgmania212121/extern/IXWebSocket-11.3.2/test/compatibility/python/websocket-client/ws_send.py
T
Martin Natano dc49af3c59 Implement NetworkManager
For now there are two methods:

- `NETWORK:IsUrlAllowed()`: Check whether access to a certain URL is allowed.
- `NETWORK:HttpRequest()`: Perform an HTTP request.

By default access to the network is disabled for all target hosts. It
can be enabled by setting `HttpEnable=1` in the preferences. Individual
hosts have to be added to `HttpAllowHosts` as a comma separated list to
allow access.

See included docs for more details on usage.
2022-01-15 22:56:08 +01:00

37 lines
832 B
Python

from websocket import *
import random
import string
import ssl
def randomString(stringLength=10):
"""Generate a random string of fixed length """
letters = string.ascii_lowercase
return ''.join(random.choice(letters) for i in range(stringLength))
st = randomString(32768)
with open('generated_file', 'w') as f:
f.write(st)
ws = create_connection("wss://echo.websocket.org/",
sslopt={"cert_reqs": ssl.CERT_NONE})
print("Sending")
frame = ABNF.create_frame(st, ABNF.OPCODE_TEXT, 0)
ws.send_frame(frame)
cont_frame = ABNF.create_frame(st, ABNF.OPCODE_CONT, 0)
ws.send_frame(cont_frame)
cont_frame = ABNF.create_frame(st, ABNF.OPCODE_CONT, 1)
ws.send_frame(cont_frame)
print("Sent")
print("Receiving...")
result = ws.recv()
if st+st+st == result:
print("Received ")
else:
print("Error")
ws.close()