-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwsHandler.py
More file actions
38 lines (30 loc) · 1.13 KB
/
Copy pathwsHandler.py
File metadata and controls
38 lines (30 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import websocket
# open WebSocket connection
def initWsConn(url):
ws = websocket.create_connection(url,timeout=3)
return ws
# send requests to target WebSocket server
def InteractWithWsSite(ws, message):
try:
# Send the message to the WebSocket server
ws.send(message)
# Receive and process the response from the WebSocket server in chunks
response = ''
while True:
chunk = ws.recv()
response += chunk
if len(chunk) < 4096: # Adjust the chunk size as needed
break
# reopens the websocket connection and move on the the next payload
except websocket.WebSocketTimeoutException:
response = "Connection Timed Out"
return response
#main function
def main():
# Example usage
websocket_url = 'ws://dvws.local:8080/authenticate-user' # Replace with the actual WebSocket URL
message_to_send = '{"auth_user":"Jw==","auth_pass":"Jw=="}' # Replace with the message you want to send
InteractWithWsSite(initWsConn(websocket_url), message_to_send)
#__main__ functiuon
if __name__ == "__main__":
main()