-
Notifications
You must be signed in to change notification settings - Fork 4
/
cookieServer6.py
40 lines (34 loc) · 947 Bytes
/
cookieServer6.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
import socket
from time import sleep
import os
host = ''
port = 5566
def setupServer():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print("Socket created.")
try:
s.bind((host, port))
except socket.error as msg:
print(msg)
print("Socket bind complete.")
return s
def setupConnection():
s.listen(100) # Allows one connection at a time. You can increase for more no. of clients
conn, address = s.accept()
print("Connected to: " + address[0] + ":" + str(address[1])) #IP and Port No.
return conn
def datarecieve(conn):
while True:
# Receive the data
ans = conn.recv(1024) # receive the data
print(ans.decode("utf-8"))
# Send the reply back to the client
conn.sendall(str.encode("Recieved"))
conn.close()
s = setupServer()
while True:
try:
conn = setupConnection()
datarecieve(conn)
except:
break