Browse Source

v5 protocol: updated all examples

pull/599/head
Miguel Grinberg 4 years ago
parent
commit
cc9b3e97bb
  1. 28
      examples/client/asyncio/fiddle_client.py
  2. 0
      examples/client/javascript/fiddle_client.js
  3. 0
      examples/client/javascript/latency_client.js
  4. 23
      examples/client/threads/fiddle_client.py
  5. 14
      examples/server/aiohttp/README.rst
  6. 2
      examples/server/aiohttp/app.html
  7. 0
      examples/server/aiohttp/app.py
  8. 11
      examples/server/aiohttp/fiddle.html
  9. 31
      examples/server/aiohttp/fiddle.py
  10. 2
      examples/server/aiohttp/latency.html
  11. 0
      examples/server/aiohttp/latency.py
  12. 19
      examples/server/aiohttp/static/fiddle.js
  13. 6
      examples/server/asgi/README.rst
  14. 2
      examples/server/asgi/app.html
  15. 0
      examples/server/asgi/app.py
  16. 11
      examples/server/asgi/fiddle.html
  17. 25
      examples/server/asgi/fiddle.py
  18. 2
      examples/server/asgi/latency.html
  19. 0
      examples/server/asgi/latency.py
  20. 19
      examples/server/asgi/static/fiddle.js
  21. 14
      examples/server/sanic/README.rst
  22. 2
      examples/server/sanic/app.html
  23. 0
      examples/server/sanic/app.py
  24. 11
      examples/server/sanic/fiddle.html
  25. 32
      examples/server/sanic/fiddle.py
  26. 2
      examples/server/sanic/latency.html
  27. 0
      examples/server/sanic/latency.py
  28. 19
      examples/server/sanic/static/fiddle.js
  29. 16
      examples/server/tornado/README.rst
  30. 2
      examples/server/tornado/app.py
  31. 47
      examples/server/tornado/fiddle.py
  32. 2
      examples/server/tornado/latency.py
  33. 19
      examples/server/tornado/static/fiddle.js
  34. 2
      examples/server/tornado/templates/app.html
  35. 11
      examples/server/tornado/templates/fiddle.html
  36. 2
      examples/server/tornado/templates/latency.html
  37. 28
      examples/server/wsgi/README.rst
  38. 0
      examples/server/wsgi/app.py
  39. 2
      examples/server/wsgi/django_example/socketio_app/static/index.html
  40. 57
      examples/server/wsgi/fiddle.py
  41. 0
      examples/server/wsgi/latency.py
  42. 19
      examples/server/wsgi/static/fiddle.js
  43. 11
      examples/server/wsgi/templates/fiddle.html
  44. 2
      examples/server/wsgi/templates/index.html
  45. 2
      examples/server/wsgi/templates/latency.html

28
examples/client/asyncio/fiddle_client.py

@ -0,0 +1,28 @@
import asyncio
import socketio
sio = socketio.AsyncClient()
@sio.event
async def connect():
print('connected to server')
@sio.event
async def disconnect():
print('disconnected from server')
@sio.event
def hello(a, b, c):
print(a, b, c)
async def start_server():
await sio.connect('http://localhost:5000')
await sio.wait()
if __name__ == '__main__':
asyncio.run(start_server())

0
examples/client/javascript/fiddle-client.js → examples/client/javascript/fiddle_client.js

0
examples/client/javascript/latency-client.js → examples/client/javascript/latency_client.js

23
examples/client/threads/fiddle_client.py

@ -0,0 +1,23 @@
import socketio
sio = socketio.Client()
@sio.event
def connect():
print('connected to server')
@sio.event
def disconnect():
print('disconnected from server')
@sio.event
def hello(a, b, c):
print(a, b, c)
if __name__ == '__main__':
sio.connect('http://localhost:5000')
sio.wait()

14
examples/server/aiohttp/README.rst

@ -23,17 +23,27 @@ time to the page.
This is an ideal application to measure the performance of the different This is an ideal application to measure the performance of the different
asynchronous modes supported by the Socket.IO server. asynchronous modes supported by the Socket.IO server.
fiddle.py
---------
This is a very simple application based on a JavaScript example of the same
name.
Running the Examples Running the Examples
-------------------- --------------------
To run these examples, create a virtual environment, install the requirements To run these examples, create a virtual environment, install the requirements
and then run:: and then run one of the following::
$ python app.py $ python app.py
or:: ::
$ python latency.py $ python latency.py
::
$ python fiddle.py
You can then access the application from your web browser at You can then access the application from your web browser at
``http://localhost:8080``. ``http://localhost:8080``.

2
examples/server/aiohttp/app.html

@ -3,7 +3,7 @@
<head> <head>
<title>python-socketio test</title> <title>python-socketio test</title>
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.4.min.js"></script> <script type="text/javascript" src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.slim.js"></script> <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.3/socket.io.min.js"></script>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
$(document).ready(function(){ $(document).ready(function(){
var socket = io.connect(); var socket = io.connect();

0
examples/server/aiohttp/app.py

11
examples/server/aiohttp/fiddle.html

@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Socket.IO Fiddle</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.3/socket.io.min.js"></script>
<script src="/static/fiddle.js"></script>
</body>
</html>

31
examples/server/aiohttp/fiddle.py

@ -0,0 +1,31 @@
from aiohttp import web
import socketio
sio = socketio.AsyncServer(async_mode='aiohttp')
app = web.Application()
sio.attach(app)
async def index(request):
with open('fiddle.html') as f:
return web.Response(text=f.read(), content_type='text/html')
@sio.event
async def connect(sid, environ):
print('connected', sid)
await sio.emit('hello', (1, 2, {'hello': 'you'}), to=sid)
@sio.event
def disconnect(sid):
print('disconnected', sid)
app.router.add_static('/static', 'static')
app.router.add_get('/', index)
if __name__ == '__main__':
web.run_app(app)

2
examples/server/aiohttp/latency.html

@ -11,7 +11,7 @@
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/smoothie/1.27.0/smoothie.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/smoothie/1.27.0/smoothie.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.slim.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.3/socket.io.min.js"></script>
<script> <script>
// socket // socket
var socket = io.connect(); var socket = io.connect();

0
examples/server/aiohttp/latency.py

19
examples/server/aiohttp/static/fiddle.js

@ -0,0 +1,19 @@
'use strict';
(function() {
const socket = io();
socket.on('connect', () => {
console.log(`connect ${socket.id}`);
});
socket.on('disconnect', () => {
console.log(`disconnect ${socket.id}`);
});
socket.on('hello', (a, b, c) => {
console.log(a, b, c);
});
})();

6
examples/server/asgi/README.rst

@ -22,6 +22,12 @@ time to the page.
This is an ideal application to measure the performance of the different This is an ideal application to measure the performance of the different
asynchronous modes supported by the Socket.IO server. asynchronous modes supported by the Socket.IO server.
fiddle.py
---------
This is a very simple application based on a JavaScript example of the same
name.
Running the Examples Running the Examples
-------------------- --------------------

2
examples/server/asgi/app.html

@ -3,7 +3,7 @@
<head> <head>
<title>python-socketio test</title> <title>python-socketio test</title>
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.4.min.js"></script> <script type="text/javascript" src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.slim.js"></script> <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.3/socket.io.min.js"></script>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
$(document).ready(function(){ $(document).ready(function(){
var socket = io.connect(); var socket = io.connect();

0
examples/server/asgi/app.py

11
examples/server/asgi/fiddle.html

@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Socket.IO Fiddle</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.3/socket.io.min.js"></script>
<script src="/static/fiddle.js"></script>
</body>
</html>

25
examples/server/asgi/fiddle.py

@ -0,0 +1,25 @@
#!/usr/bin/env python
import uvicorn
import socketio
sio = socketio.AsyncServer(async_mode='asgi')
app = socketio.ASGIApp(sio, static_files={
'/': 'fiddle.html',
'/static': 'static',
})
@sio.event
async def connect(sid, environ):
print('connected', sid)
await sio.emit('hello', (1, 2, {'hello': 'you'}), to=sid)
@sio.event
def disconnect(sid):
print('disconnected', sid)
if __name__ == '__main__':
uvicorn.run(app, host='127.0.0.1', port=5000)

2
examples/server/asgi/latency.html

@ -11,7 +11,7 @@
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/smoothie/1.27.0/smoothie.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/smoothie/1.27.0/smoothie.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.slim.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.3/socket.io.min.js"></script>
<script> <script>
// socket // socket
var socket = io.connect(); var socket = io.connect();

0
examples/server/asgi/latency.py

19
examples/server/asgi/static/fiddle.js

@ -0,0 +1,19 @@
'use strict';
(function() {
const socket = io();
socket.on('connect', () => {
console.log(`connect ${socket.id}`);
});
socket.on('disconnect', () => {
console.log(`disconnect ${socket.id}`);
});
socket.on('hello', (a, b, c) => {
console.log(a, b, c);
});
})();

14
examples/server/sanic/README.rst

@ -26,17 +26,27 @@ time to the page.
This is an ideal application to measure the performance of the different This is an ideal application to measure the performance of the different
asynchronous modes supported by the Socket.IO server. asynchronous modes supported by the Socket.IO server.
fiddle.py
---------
This is a very simple application based on a JavaScript example of the same
name.
Running the Examples Running the Examples
-------------------- --------------------
To run these examples, create a virtual environment, install the requirements To run these examples, create a virtual environment, install the requirements
and then run:: and then run one of the following::
$ python app.py $ python app.py
or:: ::
$ python latency.py $ python latency.py
::
$ python fiddle.py
You can then access the application from your web browser at You can then access the application from your web browser at
``http://localhost:8000``. ``http://localhost:8000``.

2
examples/server/sanic/app.html

@ -3,7 +3,7 @@
<head> <head>
<title>Flask-SocketIO Test</title> <title>Flask-SocketIO Test</title>
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.4.min.js"></script> <script type="text/javascript" src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.slim.js"></script> <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.3/socket.io.min.js"></script>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
$(document).ready(function() { $(document).ready(function() {
var socket = io.connect(); var socket = io.connect();

0
examples/server/sanic/app.py

11
examples/server/sanic/fiddle.html

@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Socket.IO Fiddle</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.3/socket.io.min.js"></script>
<script src="/static/fiddle.js"></script>
</body>
</html>

32
examples/server/sanic/fiddle.py

@ -0,0 +1,32 @@
from sanic import Sanic
from sanic.response import html
import socketio
sio = socketio.AsyncServer(async_mode='sanic')
app = Sanic()
sio.attach(app)
@app.route('/')
def index(request):
with open('fiddle.html') as f:
return html(f.read())
@sio.event
async def connect(sid, environ):
print('connected', sid)
await sio.emit('hello', (1, 2, {'hello': 'you'}), to=sid)
@sio.event
def disconnect(sid):
print('disconnected', sid)
app.static('/static', './static')
if __name__ == '__main__':
app.run()

2
examples/server/sanic/latency.html

@ -11,7 +11,7 @@
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/smoothie/1.27.0/smoothie.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/smoothie/1.27.0/smoothie.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.slim.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.3/socket.io.min.js"></script>
<script> <script>
// socket // socket
var socket = io.connect(); var socket = io.connect();

0
examples/server/sanic/latency.py

19
examples/server/sanic/static/fiddle.js

@ -0,0 +1,19 @@
'use strict';
(function() {
const socket = io();
socket.on('connect', () => {
console.log(`connect ${socket.id}`);
});
socket.on('disconnect', () => {
console.log(`disconnect ${socket.id}`);
});
socket.on('hello', (a, b, c) => {
console.log(a, b, c);
});
})();

16
examples/server/tornado/README.rst

@ -23,17 +23,27 @@ time to the page.
This is an ideal application to measure the performance of the different This is an ideal application to measure the performance of the different
asynchronous modes supported by the Socket.IO server. asynchronous modes supported by the Socket.IO server.
fiddle.py
---------
This is a very simple application based on a JavaScript example of the same
name.
Running the Examples Running the Examples
-------------------- --------------------
To run these examples, create a virtual environment, install the requirements To run these examples, create a virtual environment, install the requirements
and then run:: and then run one of the following::
$ python app.py $ python app.py
or:: ::
$ python latency.py $ python latency.py
::
$ python fiddle.py
You can then access the application from your web browser at You can then access the application from your web browser at
``http://localhost:8888``. ``http://localhost:5000``.

2
examples/server/tornado/app.py

@ -6,7 +6,7 @@ import tornado.web
import socketio import socketio
define("port", default=8888, help="run on the given port", type=int) define("port", default=5000, help="run on the given port", type=int)
define("debug", default=False, help="run in debug mode") define("debug", default=False, help="run in debug mode")
sio = socketio.AsyncServer(async_mode='tornado') sio = socketio.AsyncServer(async_mode='tornado')

47
examples/server/tornado/fiddle.py

@ -0,0 +1,47 @@
import os
import tornado.ioloop
from tornado.options import define, options, parse_command_line
import tornado.web
import socketio
define("port", default=5000, help="run on the given port", type=int)
define("debug", default=False, help="run in debug mode")
sio = socketio.AsyncServer(async_mode='tornado')
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.render("fiddle.html")
@sio.event
async def connect(sid, environ):
print('connected', sid)
await sio.emit('hello', (1, 2, {'hello': 'you'}), to=sid)
@sio.event
def disconnect(sid):
print('disconnected', sid)
def main():
parse_command_line()
app = tornado.web.Application(
[
(r"/", MainHandler),
(r"/socket.io/", socketio.get_tornado_handler(sio)),
],
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
debug=options.debug,
)
app.listen(options.port)
tornado.ioloop.IOLoop.current().start()
if __name__ == "__main__":
main()

2
examples/server/tornado/latency.py

@ -6,7 +6,7 @@ import tornado.web
import socketio import socketio
define("port", default=8888, help="run on the given port", type=int) define("port", default=5000, help="run on the given port", type=int)
define("debug", default=False, help="run in debug mode") define("debug", default=False, help="run in debug mode")
sio = socketio.AsyncServer(async_mode='tornado') sio = socketio.AsyncServer(async_mode='tornado')

19
examples/server/tornado/static/fiddle.js

@ -0,0 +1,19 @@
'use strict';
(function() {
const socket = io();
socket.on('connect', () => {
console.log(`connect ${socket.id}`);
});
socket.on('disconnect', () => {
console.log(`disconnect ${socket.id}`);
});
socket.on('hello', (a, b, c) => {
console.log(a, b, c);
});
})();

2
examples/server/tornado/templates/app.html

@ -3,7 +3,7 @@
<head> <head>
<title>python-socketio test</title> <title>python-socketio test</title>
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.4.min.js"></script> <script type="text/javascript" src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.slim.js"></script> <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.3/socket.io.min.js"></script>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
$(document).ready(function(){ $(document).ready(function(){
var socket = io.connect(); var socket = io.connect();

11
examples/server/tornado/templates/fiddle.html

@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Socket.IO Fiddle</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.3/socket.io.min.js"></script>
<script src="/static/fiddle.js"></script>
</body>
</html>

2
examples/server/tornado/templates/latency.html

@ -11,7 +11,7 @@
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/smoothie/1.27.0/smoothie.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/smoothie/1.27.0/smoothie.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.slim.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.3/socket.io.min.js"></script>
<script> <script>
// socket // socket
var socket = io.connect(); var socket = io.connect();

28
examples/server/wsgi/README.rst

@ -30,32 +30,42 @@ django_example
This is a version of the "app.py" application described above, that is based This is a version of the "app.py" application described above, that is based
on the Django web framework. on the Django web framework.
fiddle.py
---------
This is a very simple application based on a JavaScript example of the same
name.
Running the Examples Running the Examples
-------------------- --------------------
To run these examples, create a virtual environment, install the requirements To run these examples, create a virtual environment, install the requirements
and then run:: and then run one of the following::
$ python app.py $ python app.py
or:: ::
$ python latency.py $ python latency.py
or:: ::
$ cd django_example $ cd django_example
$ ./manage.py runserver $ ./manage.py runserver
::
$ python fiddle
You can then access the application from your web browser at You can then access the application from your web browser at
``http://localhost:5000`` (``app.py`` and ``latency.py``) or ``http://localhost:5000`` (``app.py``, ``latency.py`` and ``fiddle.py``) or
``http://localhost:8000`` (``django_example``). ``http://localhost:8000`` (``django_example``).
Near the top of the ``app.py`` and ``latency.py`` source files there is a Near the top of the ``app.py``, ``latency.py`` and ``fiddle.py`` source files
``async_mode`` variable that can be edited to swich to the other asynchornous there is a ``async_mode`` variable that can be edited to swich to the other
modes. Accepted values for ``async_mode`` are ``'threading'``, ``'eventlet'`` asynchornous modes. Accepted values for ``async_mode`` are ``'threading'``,
and ``'gevent'``. For ``django_example``, the async mode can be set in the ``'eventlet'`` and ``'gevent'``. For ``django_example``, the async mode can be
``django_example/socketio_app/views.py`` module. set in the ``django_example/socketio_app/views.py`` module.
Note 1: when using the ``'eventlet'`` mode, the eventlet package must be Note 1: when using the ``'eventlet'`` mode, the eventlet package must be
installed in the virtual environment:: installed in the virtual environment::

0
examples/server/wsgi/app.py

2
examples/server/wsgi/django_example/socketio_app/static/index.html

@ -3,7 +3,7 @@
<head> <head>
<title>Django + SocketIO Test</title> <title>Django + SocketIO Test</title>
<script type="text/javascript" src="//code.jquery.com/jquery-3.2.1.slim.min.js"></script> <script type="text/javascript" src="//code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.slim.js"></script> <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.3/socket.io.min.js"></script>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
$(document).ready(function(){ $(document).ready(function(){
var socket = io.connect(); var socket = io.connect();

57
examples/server/wsgi/fiddle.py

@ -0,0 +1,57 @@
# set async_mode to 'threading', 'eventlet', 'gevent' or 'gevent_uwsgi' to
# force a mode else, the best mode is selected automatically from what's
# installed
async_mode = None
from flask import Flask, render_template
import socketio
sio = socketio.Server(async_mode=async_mode)
app = Flask(__name__)
app.wsgi_app = socketio.WSGIApp(sio, app.wsgi_app)
@app.route('/')
def index():
return render_template('fiddle.html')
@sio.event
def connect(sid, environ):
print('connected', sid)
sio.emit('hello', (1, 2, {'hello': 'you'}), to=sid)
@sio.event
def disconnect(sid):
print('disconnected', sid)
if __name__ == '__main__':
if sio.async_mode == 'threading':
# deploy with Werkzeug
app.run(threaded=True)
elif sio.async_mode == 'eventlet':
# deploy with eventlet
import eventlet
import eventlet.wsgi
eventlet.wsgi.server(eventlet.listen(('', 5000)), app)
elif sio.async_mode == 'gevent':
# deploy with gevent
from gevent import pywsgi
try:
from geventwebsocket.handler import WebSocketHandler
websocket = True
except ImportError:
websocket = False
if websocket:
pywsgi.WSGIServer(('', 5000), app,
handler_class=WebSocketHandler).serve_forever()
else:
pywsgi.WSGIServer(('', 5000), app).serve_forever()
elif sio.async_mode == 'gevent_uwsgi':
print('Start the application through the uwsgi server. Example:')
print('uwsgi --http :5000 --gevent 1000 --http-websockets --master '
'--wsgi-file latency.py --callable app')
else:
print('Unknown async_mode: ' + sio.async_mode)

0
examples/server/wsgi/latency.py

19
examples/server/wsgi/static/fiddle.js

@ -0,0 +1,19 @@
'use strict';
(function() {
const socket = io();
socket.on('connect', () => {
console.log(`connect ${socket.id}`);
});
socket.on('disconnect', () => {
console.log(`disconnect ${socket.id}`);
});
socket.on('hello', (a, b, c) => {
console.log(a, b, c);
});
})();

11
examples/server/wsgi/templates/fiddle.html

@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Socket.IO Fiddle</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.3/socket.io.min.js"></script>
<script src="{{ url_for('static', filename='fiddle.js') }}"></script>
</body>
</html>

2
examples/server/wsgi/templates/index.html

@ -3,7 +3,7 @@
<head> <head>
<title>Flask-SocketIO Test</title> <title>Flask-SocketIO Test</title>
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.4.min.js"></script> <script type="text/javascript" src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.slim.js"></script> <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.3/socket.io.min.js"></script>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
$(document).ready(function(){ $(document).ready(function(){
var socket = io.connect(); var socket = io.connect();

2
examples/server/wsgi/templates/latency.html

@ -11,7 +11,7 @@
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/smoothie/1.27.0/smoothie.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/smoothie/1.27.0/smoothie.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.slim.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.3/socket.io.min.js"></script>
<script> <script>
// socket // socket
var socket = io.connect(); var socket = io.connect();

Loading…
Cancel
Save