Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import socket
- import time
- import threading
- os.system("clear")
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- def repeat_connect(host, port):
- s.listen(1)
- conn, addr = s.accept()
- with conn:
- print("Connection from: [%s: %s]" % (addr))
- while True:
- data = conn.recv(1024)
- if not data: break
- conn.send(data)
- def create_server(host, port):
- os.system("clear")
- print("\nAttempting to create server on\nIP: %s\nPort: %s" % (host, port))
- s.bind((host, port))
- os.system("clear")
- print("\nServer successfully created on:\nIP: %s\nPort: %s" % (host, port))
- s.listen(10)
- #conn, addr = s.accept()
- #with conn:
- # while True:
- # print("Connection from: [%s: %s]" % (addr))
- # data = conn.recv(1024)
- # if not data: break
- # conn.send(data)
- while True:
- s.listen(1)
- conn, addr = s.accept()
- print("\nConnection from: [%s: %s]" % (addr))
- with conn:
- data = conn.recv(1024)
- if not data: break
- conn.send(data)
- def get_server_info():
- while True:
- os.system("clear")
- os.system("hostname -I")
- print("\nWhich IP and Port would you like to create the server on?")
- host = input("\nIP: ")
- port = int(input("Port: ")) # port number has to be int (incase the int(intput)) was confusing...
- os.system("clear")
- print("\nIP: %s\nPort: %s" % (host, port))
- print("\nIs the information you'd like to create the server on correct?")
- correct = input("\n[y/n]: ").lower().split()
- if correct[0] == "y":
- create_server(host, port)
- elif correct[0] == "n":
- get_server_info()
- else:
- get_server_info()
- get_server_info()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement