Adding new function to send status reports on errors or sucesses.
This commit is contained in:
parent
cc934e5ec8
commit
2993f74b05
|
@ -285,9 +285,6 @@ public final class BesterConnection : Thread
|
||||||
{
|
{
|
||||||
/* TODO: Remove me */
|
/* TODO: Remove me */
|
||||||
debugPrint("fhjhfsdjhfdjhgsdkjh UUUUH:" ~e.toString());
|
debugPrint("fhjhfsdjhfdjhgsdkjh UUUUH:" ~e.toString());
|
||||||
// dispatchStatus = false;
|
|
||||||
|
|
||||||
/* TODO: Add call to `sendStatus` here as the handler failed */
|
|
||||||
|
|
||||||
/* Send error message to client */
|
/* Send error message to client */
|
||||||
sendErrorReport(payloadTag);
|
sendErrorReport(payloadTag);
|
||||||
|
@ -309,6 +306,46 @@ public final class BesterConnection : Thread
|
||||||
return true;
|
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 */
|
/* Send an error report */
|
||||||
public void sendErrorReport(string id)
|
public void sendErrorReport(string id)
|
||||||
{
|
{
|
||||||
|
|
|
@ -225,6 +225,13 @@ public final class HandlerResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
debugPrint("SEND_CLIENTS: Completed run");
|
debugPrint("SEND_CLIENTS: Completed run");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a status report here.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* TODO: Implement me */
|
||||||
|
sendErrorReport
|
||||||
}
|
}
|
||||||
else if (commandType == CommandType.SEND_SERVERS)
|
else if (commandType == CommandType.SEND_SERVERS)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,6 +20,12 @@ def sendAs(username):
|
||||||
d.send(len(bys).to_bytes(4, "little"))
|
d.send(len(bys).to_bytes(4, "little"))
|
||||||
d.send(bys.encode())
|
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)
|
# Now we can do it again (without authentication)
|
||||||
|
|
Loading…
Reference in New Issue