From 905e2c1ba6ffd29590f9830921cb1e846c042614 Mon Sep 17 00:00:00 2001 From: sachaaaaa Date: Fri, 5 Oct 2018 13:13:28 +1000 Subject: [PATCH] mock socket server to send keepalive as well as mock messages --- mockup_servers/socket_server.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mockup_servers/socket_server.py b/mockup_servers/socket_server.py index 2571cafe4..e35fd7861 100644 --- a/mockup_servers/socket_server.py +++ b/mockup_servers/socket_server.py @@ -14,12 +14,14 @@ async def hello(websocket, path): # new Uint8Array(protomessage.encode().toArrayBuffer()) message = bytes( #[8, 1, 18, 70, 10, 3, 80, 85, 84, 18, 15, 47, 97, 112, 105, 47, 118, 49, 47, 109, 101, 115, 115, 97, 103, 101, 26, 44, 8, 1, 18, 15, 109, 121, 115, 111, 117, 114, 99, 101, 97, 100, 100, 114, 101, 115, 115, 56, 1, 40, 184, 151, 213, 221, 5, 66, 15, 10, 13, 10, 11, 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 32, 99] - [8,1,18,117,10,3,80,85,84,18,15,47,97,112,105,47,118,49,47,109,101,115,115,97,103,101,26,91,8,1,18,66,48,53,57,54,51,57,53,97,55,102,48,97,54,99,97,54,51,55,57,100,52,57,99,53,97,53,56,52,49,48,51,97,52,57,50,55,52,57,55,51,99,102,53,55,97,98,49,98,54,51,48,49,51,51,48,99,99,51,51,101,97,54,102,57,52,99,56,1,40,0,66,15,10,13,10,11,104,101,108,108,111,32,119,111,114,108,100,32,99] - ) + [ + 8,1,18,117,10,3,80,85,84,18,15,47,97,112,105,47,118,49,47,109,101,115,115,97,103,101,26,91,8,1,18,66,48,53,55,51,57,102,51,54,55,50,100,55,57,52,51,56,101,57,53,53,97,55,99,99,55,55,56,52,100,98,97,53,101,97,52,98,102,56,50,55,52,54,54,53,55,55,51,99,97,102,51,101,97,98,55,48,97,50,98,57,100,98,102,101,50,99,56,1,40,0,66,15,10,13,10,11,104,101,108,108,111,32,119,111,114,108,100,32,99 + ]) # created by executing in js: # dataMessage = new textsecure.protobuf.DataMessage({body: "hello world", attachments:[], contact:[]}) # content = new textsecure.protobuf.Content({ dataMessage }) # contentBytes = content.encode().toArrayBuffer() + # - skipped encryption - # messageEnvelope = new textsecure.protobuf.Envelope({ type:1, source:"0596395a7f0a6ca6379d49c5a584103a49274973cf57ab1b6301330cc33ea6f94c", sourceDevice:1, timestamp:0, content: contentBytes}) # requestMessage = new textsecure.protobuf.WebSocketRequestMessage({id:99, verb:'PUT', path:'/api/v1/message', body: messageEnvelope.encode().toArrayBuffer()}) # protomessage = new textsecure.protobuf.WebSocketMessage({type: textsecure.protobuf.WebSocketMessage.Type.REQUEST, request: requestMessage}) @@ -30,13 +32,16 @@ async def hello(websocket, path): if not signature: print("no signature provided") - my_bytes = message counter = 0 while(True): print("sending keepalive") - await websocket.send(my_bytes) + await websocket.send(keep_alive_bytes) response = await websocket.recv() print(f"response: {response}") + if counter % 5 == 0: + await websocket.send(message) + response = await websocket.recv() + print(f"response: {response}") time.sleep(30) counter = counter + 1