Skip to content

Commit 18d0924

Browse files
committed
Update to v0.91
Small changes for easier use when using this program with another.
1 parent c5d92fc commit 18d0924

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

server.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
1-
import socket
2-
import tcp
1+
## Example use of tcp v0.91 ##
2+
## R. M. Jones ##
3+
## 01/07/2017 ##
4+
5+
import tcp #imoprts the module that is included with this file
36

47
def server():
8+
59
data =0
6-
TCP_IP = tcp.getmyip()
7-
TCP_PORT = int(input("Enter port: "))
10+
TCP_IP = tcp.getmyip() #Gets your private ip address
11+
TCP_PORT = int(input("Enter port: ")) #The port that will be open
812
BUFFER_SIZE = 20 # Normally 1024, but we want fast response
913

1014
conn = tcp.bind(TCP_IP, TCP_PORT)
1115

12-
while data != "stop":
13-
data = tcp.receive(conn, BUFFER_SIZE)
14-
if not data:
15-
conn = tcp.bind(TCP_IP, TCP_PORT)
16-
else:
17-
print ("received data:", data)
18-
19-
tcp.send(data, conn)
20-
#conn.send(data.encode()) # enumerate
21-
22-
conn.close()
16+
17+
data = tcp.receive(conn, BUFFER_SIZE)
18+
if not data:
19+
conn = tcp.bind(TCP_IP, TCP_PORT)
20+
else:
21+
return "received data: " + data, conn
22+
2323

24-
server()
24+
if __name__ == "__main__":
25+
info = 0
26+
while info != "stop":
27+
info, s = server()
28+
print(info)
29+
tcp.send(data, s)
30+
s.close()

0 commit comments

Comments
 (0)