-
-
Notifications
You must be signed in to change notification settings - Fork 575
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reorganization of examples, plus some new ones for the client
- Loading branch information
1 parent
fc5fbcf
commit 4822d81
Showing
62 changed files
with
170 additions
and
24 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 |
---|---|---|
@@ -1,25 +1,6 @@ | ||
Socket.IO Examples | ||
================== | ||
|
||
This directory contains several example Socket.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 Socket.IO applications. Look in the | ||
`server` directory for Socket.IO servers, and in the `client` directory for | ||
Socket.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 @@ | ||
Socket.IO Client Examples | ||
========================= | ||
|
||
This directory contains several example Socket.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,24 @@ | ||
Socket.IO Threading Examples | ||
============================ | ||
|
||
This directory contains example Socket.IO clients that work with the | ||
`threading` package of the Python standard library. | ||
|
||
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 Socket.IO server. | ||
|
||
Running the Examples | ||
-------------------- | ||
|
||
These examples work with the server examples of the same name. First run one | ||
of the `latency.py` versions from the `examples/server/wsgi` directory. On | ||
another terminal, then start the corresponding client:: | ||
|
||
$ 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 socketio | ||
|
||
loop = asyncio.get_event_loop() | ||
sio = socketio.AsyncClient() | ||
start_timer = None | ||
|
||
|
||
async def send_ping(): | ||
global start_timer | ||
start_timer = time.time() | ||
await sio.emit('ping_from_client') | ||
|
||
|
||
@sio.on('connect') | ||
async def on_connect(): | ||
print('connected to server') | ||
await send_ping() | ||
|
||
|
||
@sio.on('pong_from_server') | ||
async def on_pong(data): | ||
global start_timer | ||
latency = time.time() - start_timer | ||
print('latency is {0:.2f} ms'.format(latency * 1000)) | ||
await sio.sleep(1) | ||
await send_ping() | ||
|
||
|
||
async def start_server(): | ||
await sio.connect('http://localhost:5000') | ||
await sio.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,24 @@ | ||
Socket.IO Threading Examples | ||
============================ | ||
|
||
This directory contains example Socket.IO clients that work with the | ||
`threading` package of the Python standard library. | ||
|
||
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 Socket.IO server. | ||
|
||
Running the Examples | ||
-------------------- | ||
|
||
These examples work with the server examples of the same name. First run one | ||
of the `latency.py` versions from the `examples/server/wsgi` directory. On | ||
another terminal, then start the corresponding client:: | ||
|
||
$ 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 socketio | ||
|
||
sio = socketio.Client() | ||
start_timer = None | ||
|
||
|
||
def send_ping(): | ||
global start_timer | ||
start_timer = time.time() | ||
sio.emit('ping_from_client') | ||
|
||
|
||
@sio.on('connect') | ||
def on_connect(): | ||
print('connected to server') | ||
send_ping() | ||
|
||
|
||
@sio.on('pong_from_server') | ||
def on_pong(data): | ||
global start_timer | ||
latency = time.time() - start_timer | ||
print('latency is {0:.2f} ms'.format(latency * 1000)) | ||
sio.sleep(1) | ||
send_ping() | ||
|
||
|
||
if __name__ == '__main__': | ||
sio.connect('http://localhost:5000') | ||
sio.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,30 @@ | ||
Socket.IO Server Examples | ||
========================= | ||
|
||
This directory contains several example Socket.IO applications, organized by | ||
directory: | ||
|
||
wsgi | ||
---- | ||
|
||
Examples that are compatible with the WSGI protocol and frameworks. | ||
|
||
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.
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.
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