Skip to content

Commit

Permalink
Add server example friendly message when no permission to create socket
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagocoutinho committed Nov 11, 2020
1 parent 792d785 commit 88ea762
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ Creating a Modbus TCP server is easy:
port = int(port)
TCPServer.allow_reuse_address = True
app = get_server(TCPServer, (host, port), RequestHandler)
try:
app = get_server(TCPServer, (host, port), RequestHandler)
except PermissionError:
print("You don't have permission to bind on {}".format(args.bind))
print("Hint: try with a different port (ex: --bind localhost:50200)")
exit(1)
@app.route(slave_ids=[1], function_codes=[1, 2], addresses=list(range(0, 10)))
def read_data_store(slave_id, function_code, address):
Expand Down
8 changes: 7 additions & 1 deletion scripts/examples/simple_tcp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
port = int(port)

TCPServer.allow_reuse_address = True
app = get_server(TCPServer, (host, port), RequestHandler)
try:
app = get_server(TCPServer, (host, port), RequestHandler)
except PermissionError:
print("You don't have permission to bind on {}".format(args.bind))
print("Hint: try with a different port (ex: --bind localhost:50200)")
exit(1)


@app.route(slave_ids=[1], function_codes=[1, 2], addresses=list(range(0, 10)))
Expand All @@ -43,6 +48,7 @@ def write_data_store(slave_id, function_code, address, value):
"""" Set value for address. """
data_store[address] = value


if __name__ == '__main__':
try:
app.serve_forever()
Expand Down

0 comments on commit 88ea762

Please sign in to comment.