-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.py
More file actions
executable file
·51 lines (43 loc) · 1.06 KB
/
server.py
File metadata and controls
executable file
·51 lines (43 loc) · 1.06 KB
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
48
49
50
51
import socket
import sys
def create_socket():
try:
global host
global port
global s
host=""
s=socket.socket()
port=9090
except socket.error as msg:
print("Socket connection error"+str(msg))
def bind_socket():
try:
global host
global port
global s
print("Binding the port")
s.bind((host,port))
s.listen(5)
except socket.error as msg:
print("Socket binding error")
bind_socket()
def accept_socket():
conn,addr=s.accept()
print("Connection has been established with IP",addr[0]," and port",str(addr[1]))
send_command(conn)
s.close()
def send_command(conn):
while True:
ter=input()
if ter==0:
conn.close()
sys.exit()
if len(str.encode(ter)) > 0:
conn.send(str.encode(ter))
client_response=str(conn.recv(1024),"utf-8")
print(client_response,end="")
def main():
create_socket()
bind_socket()
accept_socket()
main()