mirror of
https://github.com/besterprotocol/besterd
synced 2023-12-13 21:00:32 +01:00
JSON parsing implemented
This commit is contained in:
parent
07384c86c7
commit
625f737b2a
2 changed files with 24 additions and 2 deletions
|
@ -7,7 +7,7 @@ void main()
|
|||
{
|
||||
/* TODO: Change this */
|
||||
string address = "0.0.0.0";
|
||||
ushort port = 2223;
|
||||
ushort port = 2222;
|
||||
|
||||
/* TODO: Add usage check and arguments before this */
|
||||
startServer(address, port);
|
||||
|
|
|
@ -5,6 +5,7 @@ import std.conv : to;
|
|||
import std.socket : Socket, AddressFamily, SocketType, ProtocolType, parseAddress, SocketFlags;
|
||||
import core.thread : Thread;
|
||||
import std.stdio : writeln;
|
||||
import std.json : JSONValue, parseJSON, JSONException;
|
||||
|
||||
public class BesterServer
|
||||
{
|
||||
|
@ -110,9 +111,30 @@ private class BesterConnection : Thread
|
|||
writeln("Received ", currentByte, "/", cast(uint)messageLength, " bytes");
|
||||
}
|
||||
|
||||
|
||||
/* Process the message */
|
||||
processMessage(messageBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
/* Process the received message */
|
||||
private void processMessage(byte[] messageBuffer)
|
||||
{
|
||||
/* The message as a JSONValue struct */
|
||||
JSONValue jsonMessage;
|
||||
|
||||
try
|
||||
{
|
||||
/* Convert message to JSON */
|
||||
jsonMessage = parseJSON(cast(string)messageBuffer);
|
||||
|
||||
writeln("JSON received: ", jsonMessage);
|
||||
}
|
||||
catch(JSONException exception)
|
||||
{
|
||||
/* TODO: Implement this */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue