-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtcpServer.py
47 lines (31 loc) · 868 Bytes
/
tcpServer.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
import socket
from sys import argv
script, filename = argv
def Main():
#selection of port "127.0.0.1:5555"
host = "127.0.0.1"
port = 5055
file1 = open(filename, 'a')
#setting up the port
s = socket.socket()
#starting the server
s.bind((host, port))
#how many clients to be connected
s.listen(1)
#accepting the connection
c, add = s.accept()
print "Connection Found: " + str(add)
while True:
data = c.recv(1024)
file1.write("Client: " + str(data) + "\n")
if not data:
break
print "Message found:" + "\n" + str(data)
data = raw_input("Enter the message: ")
print "Sending... " + "\n" + str(data)
c.send(data)
file1.write("Server: " + str(data) + "\n")
file1.close()
c.close()
if __name__ == "__main__":
Main()