-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtestsocket.py
More file actions
30 lines (25 loc) · 788 Bytes
/
testsocket.py
File metadata and controls
30 lines (25 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import socket,threading,select
def doListen():
try:
while True:
(readlist,writelist,exceptlist)=select.select([s],[],[s],1)
if (s in readlist):
b=s.recv(128)
print(b.decode("utf-8"),end="", sep="")
elif (s in exceptlist):
print("Exception on socket")
break
except Exception as err:
print("Connection aborted.",err)
print("Connecting...")
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect(("srtmoo.net",8492))
x=threading.Thread(target=doListen)
x.start()
print("Connected")
while True:
cmd=input(">")
if cmd=="/quit":
break
s.send((cmd+"\n").encode("utf-8"))
print("Done")