forked from omgnetwork/plasma-cash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
operator-client bi-directional event system in WebSocket
When sending transactions, the receiver client needs readltime notifications because it needs to confirm that the history has been received. And due to the clients may not always have public ip accessibility, it's easier to set a persistent connection between the server and a client, and let the server push notifications to clients. Now, the child_chain_client connects to the server in its constructor, and provides emit, on event system for easier communications. Also, the client can register its identity, like address, after connecting to the server, and the server can identify each client to send or relay messages. For example: Alice: ``` c = container.get_child_chain_client() c.emit('join', 'alice') c.on('relay', print) ``` Bob: ``` c = container.get_child_chain_client() c.emit('join', 'bob') c.emit('relay', {'dest': 'alice', 'message': 'hello'}) ``` And due to a WebSocket framework was introduced on server side, the server startup command was changed to ``` python -m plasma_cash.child_chain ``` the orignal `flask run` command will failed to start the WebSocket service.
- Loading branch information
Showing
7 changed files
with
77 additions
and
3 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
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,22 @@ | ||
import argparse | ||
|
||
from gevent import pywsgi | ||
from geventwebsocket.handler import WebSocketHandler | ||
|
||
from plasma_cash.child_chain import create_app | ||
|
||
if __name__ == '__main__': | ||
app = create_app() | ||
|
||
parser = argparse.ArgumentParser(prog=__package__) | ||
parser.add_argument('--host', default='127.0.0.1', help='Hostname to listen on.') | ||
parser.add_argument('--port', default='8546', help='Port number to listen on.') | ||
args = parser.parse_args() | ||
|
||
print('Listening on ' + args.host + ':' + args.port) | ||
server = pywsgi.WSGIServer((args.host, int(args.port)), app, handler_class=WebSocketHandler) | ||
|
||
try: | ||
server.serve_forever() | ||
except KeyboardInterrupt: | ||
pass |
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
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