/
net-test.py
48 lines (42 loc) · 1.34 KB
/
net-test.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
48
import netclient as NC
import netserver as NS
import console as C
import sys
import time
import logging
# Enable/Disable Debug prints
if False:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig()
# Run server: python net-test.py 0
# Run client: python net-test.py 1
# You can type chat messages into the client (eg. "say hello world")
def client():
# Initialize components
n = NC.client_thread(sys.argv[2],8888)
n.connect()
c = C.console(n)
c.setDaemon(True)
c.start()
# Dummy main event loop for client
while n.connected:
if n.match: # This loop will run at a pre determined rate (eg. 10 Hz)
# Pack/queue all player commands (NET:Provide methods to pack and queue)
n.send() # Send player commands (NET:Provide method to send all packets)
# Process all commands (NET:Provide access to all the commands)
# Process metrics (NET:Provide access to simplified metrics)
# Progess turn number (NET:Handle internally I think)
time.sleep(1) # Dummy frame render time
n.recv() # Recv oponent commands (NET:Provide method to recv all packets)
else:
pass
if __name__ == '__main__':
t = int(sys.argv[1])
# Client
if t:
client()
# Server
else:
n = NS.server_thread(8888,30,True)
n.start()