Advertisement
Guest User

client.py

a guest
Jan 26th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import socket
  2. import sys
  3. import os
  4. import time
  5.  
  6. os.system("clear")
  7.  
  8. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  9.  
  10. def connect(host, port):
  11. print("\nAttempting to connect to:\nIP: %s\nPort: %d" % (host, port))
  12. s.connect((host,port))
  13. print("\nSuccessfully connected to:\nIP: %s\nPort: %d" % (host, port))
  14. name = input("\nWhats your name?\nName: ")
  15. while True:
  16. message = input("%s: " % (name)).encode()
  17. s.sendall(message)
  18. data = s.recv(1024)
  19. print("Received: ", repr(data))
  20.  
  21. def get_connection_info():
  22. while True:
  23. os.system("clear")
  24. os.system("hostname -I")
  25.  
  26. print("\nWhat IP and Port would you like to connect to?")
  27. host = input("\nHost: ")
  28. port = int(input("Port: ")) # the port has to be an int, (explaining the reasoning behind the int(input))
  29.  
  30. os.system("clear")
  31. print("\nIs this the correct IP and Port number you'd like to connect to?\n\nIP: %s\nPort: %d" % (host, port))
  32.  
  33. correct = input("\n[y/n]: ").lower().split()
  34.  
  35. if correct[0] == "y":
  36. connect(host, port)
  37. elif correct[0] == "n":
  38. get_connection_info()
  39. else:
  40. get_connection_info()
  41.  
  42. get_connection_info()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement