-
-
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
1 parent
5923e7d
commit 916bd7a
Showing
50 changed files
with
269 additions
and
27 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
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 |
---|---|---|
@@ -1,26 +1,6 @@ | ||
Engine.IO Examples | ||
================== | ||
|
||
This directory contains several example Engine.IO applications, organized by | ||
directory: | ||
|
||
wsgi | ||
---- | ||
|
||
Examples that are compatible with the WSGI protocol and frameworks. | ||
|
||
aiohttp | ||
------- | ||
|
||
Examples that are compatible with the aiohttp framework for asyncio. | ||
|
||
sanic | ||
----- | ||
|
||
Examples that are compatible with the sanic framework for asyncio. | ||
|
||
|
||
tornado | ||
------- | ||
|
||
Examples that are compatible with the Tornado framework. | ||
This directory contains several example Engine.IO applications. Look in the | ||
`server` directory for Engine.IO servers, and in the `client` directory for | ||
Engine.IO clients. |
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,15 @@ | ||
Engine.IO Client Examples | ||
========================= | ||
|
||
This directory contains several example Engine.IO client applications, | ||
organized by directory: | ||
|
||
threads | ||
------- | ||
|
||
Examples that use standard Python thread concurrency. | ||
|
||
asyncio | ||
------- | ||
|
||
Examples that use Python's `asyncio` package for concurrency. |
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,35 @@ | ||
Engine.IO Threading Examples | ||
============================ | ||
|
||
This directory contains example Engine.IO clients that work with the | ||
`threading` package of the Python standard library. | ||
|
||
simple_client.py | ||
---------------- | ||
|
||
A basic application in which the client sends messages to the server and the | ||
server responds. | ||
|
||
latency_client.py | ||
----------------- | ||
|
||
In this application the client sends *ping* messages to the server, which are | ||
responded by the server with a *pong*. The client measures the time it takes | ||
for each of these exchanges. | ||
|
||
This is an ideal application to measure the performance of the different | ||
asynchronous modes supported by the Engine.IO server. | ||
|
||
Running the Examples | ||
-------------------- | ||
|
||
These examples work with the server examples of the same name. First run one | ||
of the `simple.py` or `latency.py` versions from the `examples/server` | ||
directory. On another terminal, then start the corresponding client with one | ||
of the following commands:: | ||
|
||
$ python simple_client.py | ||
|
||
or:: | ||
|
||
$ python latency_client.py |
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,37 @@ | ||
import asyncio | ||
import time | ||
import engineio | ||
|
||
loop = asyncio.get_event_loop() | ||
eio = engineio.AsyncClient() | ||
start_timer = None | ||
|
||
|
||
async def send_ping(): | ||
global start_timer | ||
start_timer = time.time() | ||
await eio.send('ping') | ||
|
||
|
||
@eio.on('connect') | ||
async def on_connect(): | ||
print('connected to server') | ||
await send_ping() | ||
|
||
|
||
@eio.on('message') | ||
async def on_message(data): | ||
global start_timer | ||
latency = time.time() - start_timer | ||
print('latency is {0:.2f} ms'.format(latency * 1000)) | ||
await eio.sleep(1) | ||
await send_ping() | ||
|
||
|
||
async def start_server(): | ||
await eio.connect('http://localhost:5000') | ||
await eio.wait() | ||
|
||
|
||
if __name__ == '__main__': | ||
loop.run_until_complete(start_server()) |
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,45 @@ | ||
import asyncio | ||
import signal | ||
import engineio | ||
|
||
loop = asyncio.get_event_loop() | ||
eio = engineio.AsyncClient() | ||
exit_event = asyncio.Event() | ||
|
||
|
||
async def send_hello(): | ||
message = 'Hello from client side!' | ||
while not exit_event.is_set(): | ||
print('sending: ' + 'Hello from client side!') | ||
await eio.send(message) | ||
try: | ||
await asyncio.wait_for(exit_event.wait(), timeout=5) | ||
except asyncio.TimeoutError: | ||
pass | ||
await eio.disconnect() | ||
|
||
|
||
@eio.on('connect') | ||
def on_connect(): | ||
print('connected to server') | ||
eio.start_background_task(send_hello) | ||
|
||
|
||
@eio.on('message') | ||
def on_message(data): | ||
print('received: ' + str(data)) | ||
|
||
|
||
def signal_handler(sig, frame): | ||
exit_event.set() | ||
print('exiting') | ||
|
||
|
||
async def start_server(): | ||
await eio.connect('http://localhost:5000') | ||
await eio.wait() | ||
|
||
|
||
if __name__ == '__main__': | ||
signal.signal(signal.SIGINT, signal_handler) | ||
loop.run_until_complete(start_server()) |
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,35 @@ | ||
Engine.IO Threading Examples | ||
============================ | ||
|
||
This directory contains example Engine.IO clients that work with the | ||
`threading` package of the Python standard library. | ||
|
||
simple_client.py | ||
---------------- | ||
|
||
A basic application in which the client sends messages to the server and the | ||
server responds. | ||
|
||
latency_client.py | ||
----------------- | ||
|
||
In this application the client sends *ping* messages to the server, which are | ||
responded by the server with a *pong*. The client measures the time it takes | ||
for each of these exchanges. | ||
|
||
This is an ideal application to measure the performance of the different | ||
asynchronous modes supported by the Engine.IO server. | ||
|
||
Running the Examples | ||
-------------------- | ||
|
||
These examples work with the server examples of the same name. First run one | ||
of the `simple.py` or `latency.py` versions from the `examples/server` | ||
directory. On another terminal, then start the corresponding client with one | ||
of the following commands:: | ||
|
||
$ python simple_client.py | ||
|
||
or:: | ||
|
||
$ python latency_client.py |
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,31 @@ | ||
import time | ||
import engineio | ||
|
||
eio = engineio.Client() | ||
start_timer = None | ||
|
||
|
||
def send_ping(): | ||
global start_timer | ||
start_timer = time.time() | ||
eio.send('ping') | ||
|
||
|
||
@eio.on('connect') | ||
def on_connect(): | ||
print('connected to server') | ||
send_ping() | ||
|
||
|
||
@eio.on('message') | ||
def on_message(data): | ||
global start_timer | ||
latency = time.time() - start_timer | ||
print('latency is {0:.2f} ms'.format(latency * 1000)) | ||
eio.sleep(1) | ||
send_ping() | ||
|
||
|
||
if __name__ == '__main__': | ||
eio.connect('http://localhost:5000') | ||
eio.wait() |
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,37 @@ | ||
import signal | ||
import threading | ||
import engineio | ||
|
||
eio = engineio.Client() | ||
exit_event = threading.Event() | ||
|
||
|
||
def send_hello(): | ||
message = 'Hello from client side!' | ||
while not exit_event.is_set(): | ||
print('sending: ' + 'Hello from client side!') | ||
eio.send(message) | ||
exit_event.wait(5) | ||
eio.disconnect() | ||
|
||
|
||
@eio.on('connect') | ||
def on_connect(): | ||
print('connected to server') | ||
eio.start_background_task(send_hello) | ||
|
||
|
||
@eio.on('message') | ||
def on_message(data): | ||
print('received: ' + str(data)) | ||
|
||
|
||
def signal_handler(sig, frame): | ||
exit_event.set() | ||
print('exiting') | ||
|
||
|
||
if __name__ == '__main__': | ||
signal.signal(signal.SIGINT, signal_handler) | ||
eio.connect('http://localhost:5000') | ||
eio.wait() |
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,31 @@ | ||
Engine.IO Server Examples | ||
========================= | ||
|
||
This directory contains several example Engine.IO server applications, | ||
organized by directory: | ||
|
||
wsgi | ||
---- | ||
|
||
Examples that are compatible with the WSGI specification. | ||
|
||
asgi | ||
---- | ||
|
||
Examples that are compatible with the ASGI specification. | ||
|
||
aiohttp | ||
------- | ||
|
||
Examples that are compatible with the aiohttp framework for asyncio. | ||
|
||
sanic | ||
----- | ||
|
||
Examples that are compatible with the sanic framework for asyncio. | ||
|
||
|
||
tornado | ||
------- | ||
|
||
Examples that are compatible with the Tornado framework. |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.