Skip to content

Commit c5d92fc

Browse files
committed
Example Piece
This is only an example program for the moment which must be used in order for the TCP module to be able to connect to the other computer. This will be removed/replaced once I've created a better program/system for the server/hosting computer.
1 parent 5323af1 commit c5d92fc

1 file changed

Lines changed: 22 additions & 15 deletions

File tree

server.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
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)
2+
import tcp
93

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()
4+
def server():
5+
data =0
6+
TCP_IP = tcp.getmyip()
7+
TCP_PORT = int(input("Enter port: "))
8+
BUFFER_SIZE = 20 # Normally 1024, but we want fast response
9+
10+
conn = tcp.bind(TCP_IP, TCP_PORT)
11+
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()
23+
24+
server()

0 commit comments

Comments
 (0)