Skip to content

Commit ee7cad1

Browse files
authored
Merge pull request #1 from RhysMJ2/server
Merge Server v0.92
2 parents 5323af1 + 6181583 commit ee7cad1

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

server.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
1-
import socket
2-
data =0
3-
TCP_IP = '192.168.1.8'
4-
TCP_PORT = 5005
5-
BUFFER_SIZE = 20 # Normally 1024, but we want fast response
6-
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
7-
s.bind((TCP_IP, TCP_PORT))
8-
s.listen(1)
1+
## Example use of tcp v0.92 ##
2+
## R. M. Jones ##
3+
## 01/07/2017 ##
94

10-
conn, addr = s.accept()
11-
print ('Connection address:', addr)
12-
while data != "stop":
13-
data = conn.recv(BUFFER_SIZE).decode()
14-
if not data: break
15-
print ("received data:", data)
16-
conn.send(data.encode()) # echo
17-
conn.close()
5+
import tcp #imoprts the module that is included with this file
6+
7+
def server(BUFFER_SIZE, TCP_IP=tcp.getmyip(), TCP_PORT=5050):
8+
9+
data =0
10+
#TCP_IP = tcp.getmyip() #Gets your private ip address
11+
#TCP_PORT = int(input("Enter port: ")) #The port that will be open
12+
BUFFER_SIZE = 20 # Normally 1024, but we want fast response
13+
14+
conn = tcp.bind(TCP_IP, TCP_PORT)
15+
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+
23+
24+
if __name__ == "__main__":
25+
info = 0
26+
while info != "stop":
27+
info, s = server(20)
28+
print(info)
29+
tcp.send(info, s)
30+
s.close()

0 commit comments

Comments
 (0)