File: server_receive.py

package info (click to toggle)
python-engineio 4.12.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 944 kB
  • sloc: python: 10,594; makefile: 15; sh: 6
file content (37 lines) | stat: -rw-r--r-- 962 bytes parent folder | download | duplicates (3)
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
import io
import sys
import time
import engineio


def test(eio_version, payload):
    s = engineio.Server()
    start = time.time()
    count = 0
    s.handle_request({
        'REQUEST_METHOD': 'GET',
        'QUERY_STRING': eio_version,
    }, lambda s, h: None)
    sid = list(s.sockets.keys())[0]
    while True:
        environ = {
            'REQUEST_METHOD': 'POST',
            'QUERY_STRING': eio_version + '&sid=' + sid,
            'CONTENT_LENGTH': '6',
            'wsgi.input': io.BytesIO(payload)
        }
        s.handle_request(environ, lambda s, h: None)
        count += 1
        if time.time() - start >= 5:
            break
    return count


if __name__ == '__main__':
    eio_version = 'EIO=4'
    payload = b'4hello'
    if len(sys.argv) > 1 and sys.argv[1] == '3':
        eio_version = 'EIO=3'
        payload = b'\x00\x06\xff4hello'
    count = test(eio_version, payload)
    print('server_receive:', count, 'packets received.')