-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
50 lines (35 loc) · 1.51 KB
/
client.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
49
50
"""
Implements an Evolution client with the silly player strategy.
The client connects to an evolution server on the given host and port and listens for, processes and
responds to messages.
"""
import socket
from argparse import ArgumentParser
from evolution.dealer.remote_dealer import RemoteDealer
from evolution.player.dummy_player import DummyPlayer
DEFAULT_HOST = "127.0.0.1"
DEFAULT_PORT = 45679
HELLO_MESSAGE = "hi"
def main(host, port):
""" Connects to an Evolution server on the given host/port, performs the sign up sequence and
then continuously listens for messages from the server and responds accordingly.
:param host: evolution host
:param port: evolution port
"""
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
player = DummyPlayer(1)
dealer = RemoteDealer(s, player)
print("Sending hello message: \"{}\"".format(HELLO_MESSAGE))
dealer.send(HELLO_MESSAGE)
print("Response received: {}".format(dealer.receive()))
dealer.main()
def parse_args():
""" Parses command-line arguments. """
parser = ArgumentParser(description="Launches a new Evolution client, which tries to connect to the given server")
parser.add_argument("-i", "--host", help="server host to connect to", default=DEFAULT_HOST)
parser.add_argument("-p", "--port", help="server port to connect to", type=int, default=DEFAULT_PORT)
return parser.parse_args()
if __name__ == "__main__":
args = parse_args()
main(args.host, args.port)