-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_side.py
47 lines (40 loc) · 1.25 KB
/
server_side.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#! /usr/bin/python
import sys
import subprocess
import socket
port = 1234
host = "00.00.00.00"
soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
soc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
soc.bind((host, port))
soc.listen(10)
conn, addr = soc.accept()
Rip, Rport = addr
Lip, Lport = conn.getsockname()
print(" Server Connected to :: {}".format(Rip))
conn.send("this is connected sucessfully\n".encode())
conn.send(f"{Lip} :: ".encode())
while 1:
data = conn.recv(1024)
if not data:
break
data = data.decode().strip()
if data == "quit":
print(f"{Rip} :: bye bye....")
conn.send(f"{Lip} :: bye bye.... ".encode())
conn.close()
conn, addr = soc.accept()
print(" Server Connected to :: {}".format(Rip))
conn.send("this is connected sucessfully\n".encode())
Rip, Rport = addr
Lip, Lport = conn.getsockname()
conn.send(f"{Lip} :: ".encode())
elif data == "close":
conn.send(f"{Rip} :: Server is closing :: bye bye guy :: >﹏<".encode())
conn.close()
soc.close()
print("Server is closing :: bye bye guy :: >﹏<")
break
else:
print(f"{Rip} :: {data}")
conn.send(f"{Lip} :: ".encode())