-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.py
41 lines (31 loc) · 959 Bytes
/
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
from io import TextIOWrapper
import pexpect
# pip install pexpect
import sys
num_servers = 3
num_clients = 3
servers = []
clients = []
def start_servers(n):
for i in range(1, num_servers + 1):
server = pexpect.spawn("java -jar target/ChatServer-1.0.0-jar-with-dependencies.jar s" + str(i) + " conf",
encoding='utf-8')
server.logfile = sys.stdout
servers.append(server)
def start_clients(n):
for i in range(num_clients):
client = pexpect.spawn('java -jar ChatClient.jar --host localhost --port 4444 -i "Alice" -d', encoding='utf-8')
client.logfile = sys.stdout
clients.append(client)
try:
# start_servers(num_servers)
start_clients(num_clients)
clients[0].sendline("Hello")
clients[0].expect("Hello")
finally:
for s in servers:
s.close(force=True)
for c in clients:
c.close(force=True)
if __name__ == '__main__':
pass