OLD | NEW |
---|---|
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
Adam Rice
2014/07/14 10:31:30
Update copyright message.
Also, you need to add a
yhirano
2014/07/14 11:24:35
Done.
| |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import struct | 5 import struct |
Adam Rice
2014/07/14 10:31:31
Not used.
yhirano
2014/07/14 11:24:36
Done.
| |
6 | 6 |
7 numOpenConnections = 0 | |
8 numClosedConnections = 0 | |
9 | |
7 from mod_pywebsocket import handshake | 10 from mod_pywebsocket import handshake |
Adam Rice
2014/07/14 10:31:30
Neither mod_pywebsocket import is used.
yhirano
2014/07/14 11:24:36
Done.
| |
8 from mod_pywebsocket import stream | 11 from mod_pywebsocket import stream |
9 | 12 |
10 | 13 |
11 def web_socket_do_extra_handshake(_request): | 14 def web_socket_do_extra_handshake(request): |
12 pass | 15 global numOpenConnections |
16 numOpenConnections += 1 | |
13 | 17 |
14 | 18 |
15 def web_socket_transfer_data(request): | 19 def web_socket_transfer_data(request): |
20 request.ws_stream.send_message('open: %d, closed: %d' % | |
21 (numOpenConnections, numClosedConnections), binary=False) | |
16 # Just waiting... | 22 # Just waiting... |
17 request.ws_stream.receive_message() | 23 request.ws_stream.receive_message() |
18 | 24 |
19 | 25 |
20 def web_socket_passive_closing_handshake(request): | 26 def web_socket_passive_closing_handshake(request): |
21 code = struct.pack('!H', 3004) | 27 global numOpenConnections |
22 packet = stream.create_close_frame(code + 'split test'.encode('utf-8')) | 28 global numClosedConnections |
23 request.connection.write(packet[:1]) | 29 numOpenConnections -= 1 |
24 request.connection.write(packet[1:]) | 30 numClosedConnections += 1 |
25 raise handshake.AbortedByUserException('Abort the connection') | 31 return (1000, '') |
OLD | NEW |