Adding new function to send status reports on errors or sucesses.

This commit is contained in:
Tristan B. Kildaire 2020-05-14 11:08:27 +02:00
parent cc934e5ec8
commit 2993f74b05
3 changed files with 53 additions and 3 deletions

View File

@ -285,9 +285,6 @@ public final class BesterConnection : Thread
{
/* TODO: Remove me */
debugPrint("fhjhfsdjhfdjhgsdkjh UUUUH:" ~e.toString());
// dispatchStatus = false;
/* TODO: Add call to `sendStatus` here as the handler failed */
/* Send error message to client */
sendErrorReport(payloadTag);
@ -309,6 +306,46 @@ public final class BesterConnection : Thread
return true;
}
public enum StatusType
{
SUCCESS,
FAILURE
}
/**
* Send a status report for the message with id
* `id` of type `StatusType`.
*/
public void sendStatusReport(StatusType statusType, string id)
{
/* Construct the response */
JSONValue statusMessage;
/* Construct the haeder block */
JSONValue headerBlock;
headerBlock["status"] = statusType == 0 ? "good" : "bad";
/* Attach the header block */
statusMessage["header"] = headerBlock;
/* Create the payload block */
JSONValue payloadBlock;
payloadBlock["id"] = id;
/* Attach the payload block */
statusMessage["payload"] = payloadBlock;
try
{
/* Send the message */
sendMessage(clientConnection, statusMessage);
}
catch(NetworkException e)
{
debugPrint("Error sending status message");
}
}
/* Send an error report */
public void sendErrorReport(string id)
{

View File

@ -225,6 +225,13 @@ public final class HandlerResponse
}
debugPrint("SEND_CLIENTS: Completed run");
/**
* Send a status report here.
*/
/* TODO: Implement me */
sendErrorReport
}
else if (commandType == CommandType.SEND_SERVERS)
{

View File

@ -20,6 +20,12 @@ def sendAs(username):
d.send(len(bys).to_bytes(4, "little"))
d.send(bys.encode())
length=int.from_bytes(list(d.recv(4)), "little")
print(length)
receivedDataBytes = d.recv(length)
receivedData = list(receivedDataBytes)
print(receivedDataBytes.decode())
# Now we can do it again (without authentication)