Skip to content

Commit 05df765

Browse files
authored
Merge pull request xilibi2003#2 from mbeigel/choose-port
Add option to choose port from command line
2 parents dbdf10e + 79b8df1 commit 05df765

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ This is the source code for my post on [Building a Blockchain](https://medium.co
66

77
1. Make sure [Python 3.6+](https://www.python.org/downloads/) is installed
88
1. Install requirements: `$ pip install -r requirements.txt`
9-
1. Run the server: `$ python blockchain.py`
9+
1. Run the server:
10+
* `$ python blockchain.py`
11+
* `$ python blockchain.py -p 5001`
12+
* `$ python blockchain.py --port 5002`
1013

1114
## Contributing
1215

blockchain.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,11 @@ def consensus():
279279

280280

281281
if __name__ == '__main__':
282-
app.run(host='0.0.0.0', port=5000)
282+
from argparse import ArgumentParser
283+
284+
parser = ArgumentParser()
285+
parser.add_argument('-p', '--port', default=5000, type=int, help='port to listen on')
286+
args = parser.parse_args()
287+
port = args.port
288+
289+
app.run(host='0.0.0.0', port=port)

0 commit comments

Comments
 (0)