Save experiments
This commit is contained in:
parent
2e2496cd4c
commit
7254172545
7 changed files with 121 additions and 0 deletions
52
experiments/client1.py
Normal file
52
experiments/client1.py
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import requests
|
||||
|
||||
|
||||
def get_packets(content):
|
||||
packets = []
|
||||
index = 0
|
||||
content_length = len(content)
|
||||
while index < content_length:
|
||||
index, packet_length = read_packet_length(content, index)
|
||||
index, packet = read_packet(content, index, packet_length)
|
||||
packets.append((packet[0], packet[1:]))
|
||||
return packets
|
||||
|
||||
|
||||
def read_packet_length(content, index):
|
||||
while ord(content[index]) != 0:
|
||||
index += 1
|
||||
index += 1
|
||||
packet_length_string = ''
|
||||
while ord(content[index]) != 255:
|
||||
packet_length_string += str(ord(content[index]))
|
||||
index += 1
|
||||
return index, int(packet_length_string)
|
||||
|
||||
|
||||
def read_packet(content, index, packet_length):
|
||||
while ord(content[index]) == 255:
|
||||
index += 1
|
||||
packet = content[index:index + packet_length]
|
||||
return index + packet_length, packet
|
||||
|
||||
|
||||
base_url = 'http://localhost:9000'
|
||||
session = requests.Session()
|
||||
# Establish engine.io connection
|
||||
response = session.get(
|
||||
base_url + '/socket.io/?EIO=3&transport=polling&t=1416156610842-0')
|
||||
packets = get_packets(response.content)
|
||||
for packet_type, packet in packets:
|
||||
print packet_type, packet
|
||||
packet_type, packet = packets[0]
|
||||
import json
|
||||
packet_json = json.loads(packet)
|
||||
print packet_json
|
||||
print packet_json['pingInterval']
|
||||
print packet_json['pingTimeout']
|
||||
print packet_json['sid']
|
||||
# Establish socket.io connection
|
||||
# Receive socket.io event
|
||||
# Send socket.io event
|
||||
# Send socket.io ping
|
||||
# Receive socket.io pong
|
||||
Loading…
Add table
Add a link
Reference in a new issue