Skip to content

Commit

Permalink
Merge pull request #56 from openziti/handle-no-file-better
Browse files Browse the repository at this point in the history
handle a missing file better in sample client
  • Loading branch information
dovholuknf authored Oct 26, 2023
2 parents 19b81f5 + 8e3c9e4 commit ab1bb1b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions sample/ziti-echo-server/ziti-echo-client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@
import openziti
import socket

def netcat_client(ziti_id, service, port):
def netcat_client(ziti_id, service):
try:
zitiContext = openziti.load(ziti_id)
client = openziti.socket(type = socket.SOCK_STREAM) #socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except Exception as e:
print(f'could not find identity file: {e}')
return

try:
client = openziti.socket(type = socket.SOCK_STREAM) #socket.socket(socket.AF_INET, socket.SOCK_STREAM)
port = 65535
client.connect((service, port))
print(f"Connected to {service}:{port}")
print(f"Connected to {service}:there_is_no_port")

while True:
user_input = input("Enter a message: ")
Expand All @@ -35,7 +40,7 @@ def netcat_client(ziti_id, service, port):
print("Server response:", data.decode("utf-8"))

except ConnectionRefusedError:
print(f"Connection to {service}:{port} refused.")
print(f"Connection to {service}:there_is_no_port refused.")
except KeyboardInterrupt:
print("\nConnection closed.")
except Exception as e:
Expand All @@ -44,4 +49,4 @@ def netcat_client(ziti_id, service, port):
client.close()

if __name__ == "__main__":
netcat_client(sys.argv[1], sys.argv[2], int(sys.argv[3]))
netcat_client(sys.argv[1], sys.argv[2])

0 comments on commit ab1bb1b

Please sign in to comment.