mirror of
https://github.com/besterprotocol/besterd
synced 2023-12-13 21:00:32 +01:00
Work in progress
This commit is contained in:
parent
0cebc13dab
commit
7b503e5cfa
|
@ -231,6 +231,9 @@ private class BesterConnection : Thread
|
|||
debugPrint("Dispatching payload [" ~ payloadType ~ "]");
|
||||
debugPrint("Payload: " ~ payload.toPrettyString());
|
||||
|
||||
/* Status of dispatch */
|
||||
bool dispatchStatus = true;
|
||||
|
||||
/* Lookup the payloadType handler */
|
||||
MessageHandler chosenHandler;
|
||||
|
||||
|
@ -281,18 +284,77 @@ private class BesterConnection : Thread
|
|||
/* TODO: Get response */
|
||||
debugPrint("Waiting for response from handler for \"" ~ chosenHandler.getPluginName() ~ "\".");
|
||||
|
||||
/* TODO: Loop for size */
|
||||
/* Construct a buffer to receive into */
|
||||
byte[] receiveBuffer;
|
||||
|
||||
/* The current byte */
|
||||
uint currentByte = 0;
|
||||
|
||||
/* The amount of bytes received */
|
||||
long bytesReceived;
|
||||
|
||||
/* Loop consume the next 4 bytes */
|
||||
while(currentByte < 4)
|
||||
{
|
||||
/* Temporary buffer */
|
||||
byte[4] tempBuffer;
|
||||
|
||||
/* Read at-most 4 bytes */
|
||||
bytesReceived = handlerSocket.receive(tempBuffer);
|
||||
|
||||
/* If there was an error reading from the socket */
|
||||
if(!(bytesReceived > 0))
|
||||
{
|
||||
/* TODO: Error handling */
|
||||
debugPrint("Error receiving from UNIX domain socket");
|
||||
}
|
||||
/* If there is no error reading from the socket */
|
||||
else
|
||||
{
|
||||
/* Add the read bytes to the *real* buffer */
|
||||
receiveBuffer ~= tempBuffer[0..bytesReceived];
|
||||
|
||||
/* Increment the byte counter */
|
||||
currentByte += bytesReceived;
|
||||
}
|
||||
}
|
||||
|
||||
/* Response message length */
|
||||
int messageLength = *cast(int*)receiveBuffer.ptr;
|
||||
writeln("Message length is: ", cast(uint)messageLength);
|
||||
|
||||
/* Response message buffer */
|
||||
byte[] fullMessage;
|
||||
|
||||
/* Reset the byte counter */
|
||||
currentByte = 0;
|
||||
|
||||
while(currentByte < messageLength)
|
||||
{
|
||||
debugPrint("dhjkh");
|
||||
}
|
||||
|
||||
/* TODO: Loop for size (4 bytes, little endian) */
|
||||
|
||||
|
||||
//int messageLength = 0;
|
||||
|
||||
/* TODO: Loop for collect message */
|
||||
|
||||
|
||||
/* TODO: Set dispatchStatus */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* TODO: Error handling */
|
||||
debugPrint("No message handler for payload type \"" ~ payloadType ~ "\" found.");
|
||||
dispatchStatus = false;
|
||||
}
|
||||
|
||||
/* TODO: Set return value */
|
||||
return true;
|
||||
debugPrint("Dispatch status: " ~ to!(string)(dispatchStatus));
|
||||
|
||||
return dispatchStatus;
|
||||
}
|
||||
|
||||
/* Process the received message */
|
||||
|
|
|
@ -3,7 +3,7 @@ import json
|
|||
|
||||
def basicTest():
|
||||
d=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
d.connect(("127.0.0.1",2222))
|
||||
d.connect(("127.0.0.1",2223))
|
||||
bys=json.dumps({"header":{"authentication":{"username":"tbk", "password":"passwd"},"type":"type1", "scope":"poes"},"payload":"ABBA"})
|
||||
print(bys)
|
||||
d.send(bytes([len(bys),0,0,0]))
|
||||
|
|
|
@ -5,8 +5,10 @@ def runTest():
|
|||
d=socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
d.bind("../aSock")
|
||||
d.listen()
|
||||
s = d.accept()[0]
|
||||
print(list(s.recv(130)))
|
||||
while True:
|
||||
s = d.accept()[0]
|
||||
print(list(s.recv(130)))
|
||||
print(s.send(bytes([4,0,0,0,65,66,66,65])))
|
||||
|
||||
while True: pass
|
||||
|
||||
|
|
Loading…
Reference in a new issue