Reputation:
I want to be able to open a new python script in a new terminal, without ending the other. Im trying to create a server with one script dishing out all the clients to new scripts, but it wont work if the other script is ended.
is there a way to fix this?
here are some of my code
starter:
import socket; import time
import os
def clear():
os.system('cls' if os.name == 'nt' else 'clear')
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ip = socket.gethostbyname(socket.gethostname())
print(ip, "thats da ip")
port = 8080
print(port, "da port")
s.bind((ip, port))
print("binded")
def idk():
s.listen(1)
c, a = s.accept()
print(f"connection from {a}")
print("authenticating")
time.sleep(1)
g = c.recv(300).decode("utf-8")
if g == ">><<":
print("accepted")
time.sleep(3)
print("starting script")
time.sleep(2)
clear()
os.system("main.py")
print("script started")
while True:
e = open("connection_script", "r")
p = e.read()
e.close()
if p == "":
pass
else:
print(f"port is {p}")
print("sending port")
c.sendall(bytes(p, "utf-8"))
print("ending...")
time.sleep(2)
s.close()
else:
print("failed to pass")
time.sleep(1)
clear()
c, a = None
pass
idk()
the other script:
file_list = ">file<list<"
connection = "connection_script"
import time
import os
import socket
def_size = 0
req_size = 900
lv1_size = 1200
admin_size = 10000000000
wait_time = 1
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ip = socket.gethostbyname(socket.gethostname())
print(f"ip = {ip}")
time.sleep(1)
print("finding open port")
j = 0
while True:
j+=1
print(j)
try:
s.bind((ip, j))
port = j
break
except:
print("failed")
time.sleep(1)
def clear():
os.system('cls' if os.name == 'nt' else 'clear')
clear()
time.sleep(2)
print(f"port is {port}")
time.sleep(2)
clear()
print("opening connection for client")
time.sleep(1)
s.listen(1)
clear()
e = open(connection, "w")
e.write(str(port))
e.close()
time.sleep(0.1)
print("conection for client open")
time.sleep(wait_time)
e = open(connection, "w")
e.write("")
e.close()
c, a = s.accept()
print(f"connection made by {a}, conn is {c}")
time.sleep(1)
e = open("_file_list_", "r")
p = e.read()
e.close()
s.sendall(bytes(p, "utf-8"))
the client im using:
import socket
import time
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ip = "192.168.1.65"
port = 8080
s.connect((ip, port))
s.sendall(bytes(">><<", "utf-8"))
b = s.recv(300)
print(b)
s.close()
s.connect((ip, b))
while True:
print(s.recv(3000))
s.sendall(bytes(input(), "utf-8"))
Upvotes: 0
Views: 46
Reputation: 213
If you are using windows you can open multiple "windows command prompt" and if you are using linux based os you can open multiple "Terminals".
Upvotes: 0
Reputation: 321
Yo man if u r using PyCharm do this :
if u DONT have Pycharm do this(windows) :
WORKS ONLY FOR PYTHON!!!!!!
Upvotes: 2