OLD | NEW |
1 from mod_pywebsocket import common | 1 from mod_pywebsocket import common |
2 from mod_pywebsocket import stream | 2 from mod_pywebsocket import stream |
3 | 3 |
4 | 4 |
5 def web_socket_do_extra_handshake(request): | 5 def web_socket_do_extra_handshake(request): |
6 pass | 6 pass |
7 | 7 |
8 | 8 |
9 def web_socket_transfer_data(request): | 9 def web_socket_transfer_data(request): |
10 messages_to_send = [['Hello, ', 'world!'], | 10 messages_to_send = [['Hello, ', 'world!'], |
11 ['', 'Hello, ', '', 'world!', ''], | 11 ['', 'Hello, ', '', 'world!', ''], |
12 ['', '', ''], | 12 ['', '', ''], |
13 [chr(i) for i in xrange(256)]] | 13 [chr(i) for i in xrange(256)]] |
14 for message_list in messages_to_send: | 14 for message_list in messages_to_send: |
15 for index, message in enumerate(message_list): | 15 for index, message in enumerate(message_list): |
16 # FIXME: Should use better API to send binary messages when pywebsoc
ket supports it. | 16 # FIXME: Should use better API to send binary messages when pywebsoc
ket supports it. |
17 if index == 0: | 17 if index == 0: |
18 opcode = common.OPCODE_BINARY | 18 opcode = common.OPCODE_BINARY |
19 else: | 19 else: |
20 opcode = common.OPCODE_CONTINUATION | 20 opcode = common.OPCODE_CONTINUATION |
21 if index < len(message_list) - 1: | 21 if index < len(message_list) - 1: |
22 final = 0 | 22 final = 0 |
23 else: | 23 else: |
24 final = 1 | 24 final = 1 |
25 header = stream.create_header(opcode, len(message), final, 0, 0, 0,
0) | 25 header = stream.create_header(opcode, len(message), final, 0, 0, 0,
0) |
26 request.connection.write(header + message) | 26 request.connection.write(header + message) |
OLD | NEW |