diff --git a/app.py b/app.py new file mode 100644 index 00000000..4e283776 --- /dev/null +++ b/app.py @@ -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) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..fe6b366b --- /dev/null +++ b/requirements.txt @@ -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 diff --git a/static/engine.io.js.2 b/static/engine.io.js.2 new file mode 100755 index 00000000..80a8103d --- /dev/null +++ b/static/engine.io.js.2 @@ -0,0 +1,3409 @@ +!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.eio=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o