-
Notifications
You must be signed in to change notification settings - Fork 0
/
est_ds_message_protocol copy.py
44 lines (35 loc) · 1.3 KB
/
est_ds_message_protocol copy.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
# Cole Thompson / Nathan Yang
# 36762668 / 63942782
import ds_client, socket, ds_protocol, time
server = "168.235.86.101"
port = 3021
username = "hellocookiedough"
password = 'thisisapassword'
def message(client:socket, token:str):
"""This function posts a message to the server given a token and message."""
stamp = time.time() # Create a timestamp
post_msg = {"token": token, "directmessage": {"entry": "Hello World!","recipient":"ohhimark", "timestamp": stamp}}
resp = ds_client._connect(post_msg, client)
x = ds_protocol._response(resp)
return x
def request(client, message, token):
post_msg = {"token": token, "directmessage": message}
resp = ds_client._connect(post_msg, client)
x = ds_protocol._response(resp)
return x
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as c:
try:
# Connect to the server
c.settimeout(3)
c.connect((server, port))
print(f"client connected to {server} on {port}")
except:
print("Was not able to connect to server/port.")
token = ds_client.join(c, username, password)
resp = message(c, token)
assert resp == "Direct message sent"
resp = request(c, "new", token)
assert type(resp) == list
resp = request(c, "all", token)
assert type(resp) == list