-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1d53a10
Showing
5 changed files
with
7,528 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import json | ||
|
||
from eventlet import wsgi | ||
import eventlet | ||
from flask import Flask, render_template, abort, request | ||
import six | ||
|
||
|
||
app = Flask(__name__) | ||
app.debug = True | ||
|
||
|
||
(OPEN, CLOSE, PING, PONG, MESSAGE, UPGRADE) = (0, 1, 2, 3, 4, 5) | ||
|
||
|
||
def encode_packet(packet_type, data=None): | ||
encoded_data = b'' | ||
if isinstance(data, six.string_types): | ||
encoded_data = data.encode('utf-8') | ||
elif isinstance(data, dict): | ||
encoded_data = json.dumps(data, separators=(',', ':')).encode('utf-8') | ||
else: | ||
encoded_data = data | ||
return six.int2byte(packet_type + 48) + encoded_data | ||
|
||
|
||
def encode_payload(packets=None): | ||
payload = b'' | ||
for packet in packets: | ||
packet_len = len(packet) | ||
binary_len = b'' | ||
while packet_len != 0: | ||
binary_len = six.int2byte(packet_len % 10) + binary_len | ||
packet_len = int(packet_len / 10) | ||
payload += b'\0' + binary_len + b'\xff' + packet | ||
return payload | ||
|
||
|
||
@app.route('/') | ||
def index(): | ||
return render_template('index.html') | ||
|
||
|
||
@app.route('/engine.io/', methods=['GET', 'POST']) | ||
def engine_io(): | ||
if 'sid' not in request.args: | ||
return encode_payload([encode_packet(OPEN, data={'upgrades':[], 'pingTimeout': 60000, 'pingInterval': 25000, 'sid': '123456'})]), 200, {'Content-Type': 'application/octet-stream', 'Set-Cookie': 'io=123456', 'Access-Control-Allow-Origin': '*'} | ||
if request.method == 'POST': | ||
print(request.data) | ||
return 'ok' | ||
return 'ok' | ||
|
||
if __name__ == '__main__': | ||
# app.run(debug=True) | ||
wsgi.server(eventlet.listen(('localhost', 5000)), app) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
eventlet==0.17.4 | ||
Flask==0.10.1 | ||
greenlet==0.4.7 | ||
itsdangerous==0.24 | ||
Jinja2==2.7.3 | ||
MarkupSafe==0.23 | ||
six==1.9.0 | ||
Werkzeug==0.10.4 | ||
wheel==0.24.0 |
Oops, something went wrong.