Skip to content

Commit

Permalink
alpha 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sujaldev committed Sep 18, 2021
1 parent 48d9888 commit 5da73d0
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import pickle
import socket

from server import Server
from client import Client


def get_auth_token():
try:
with open("auth.token", "rb") as auth_file:
return pickle.load(auth_file)
except FileNotFoundError:
with open("auth.token", "wb") as auth_file:
token = input("Enter your ngrok auth token: ")
pickle.dump(token, auth_file)
return token


def host():
token = get_auth_token()
Server(token)


def join():
tunnel_url = input("Enter joining code: ").split(":")
host_ip = socket.gethostbyname(tunnel_url[0])
host_port = int(tunnel_url[1])
server = (host_ip, host_port)

client_name = input("Enter your display name: ")

Client(server, client_name)


def main():
print("Welcome to ngrok chat, let's begin:",
"Do you want to host a server or join a server?",
"\t1: Host",
"\t2: Join", sep="\n")
choice = input(">>> ")
if choice == "1":
host()
elif choice == "2":
join()
else:
print("No such choice, exiting...")


if __name__ == '__main__':
main()

0 comments on commit 5da73d0

Please sign in to comment.