net = require('net');

server = net.createServer(function (socket) {

    console.log("Connection from: " + socket.remoteAddress);

    var testIndex = 0;

    var tests = ["1+1", "2+2", "3-4", "4 * 4", "9/0"];
    var results = ["2" , "4", "-1" , "16", "ERROR"];

    var client_md5 = "";

    socket.on('data', function (data) {
       if(data.toString().startsWith("HELLO"))
       {
            var message = data.toString().substring(0, data.toString().indexOf("\n"));
            console.log("HELLO message: "+ message);
            client_md5 = message.substring(5, data.toString().indexOf("\n") - 1);
            console.log("Client MD5: " + client_md5);
            sendTest(socket, testIndex);

       }
       else if(data.toString().startsWith("RESULT"))
       {
            if(client_md5.length == 0)
            {
                socket.end();
                return;
            }
            var message = data.toString().substring(0, data.toString().indexOf("\n"));
            console.log("RESULT message: " + message);
            var result = message.substring(7, data.toString().indexOf("\n") -1);
            console.log("Result of test: " + tests[testIndex]);
            console.log("Expected: " + results[testIndex]);
            console.log("Obtained: " + result);
            if(result == results[testIndex]) {
                console.log("Correct result");
            } else {
                console.error("Incorrect result");
                socket.end();
                return;
            }
            if(++testIndex < tests.length)
            {
                sendTest(socket, testIndex);
            }
            else
            {
                sendBye(socket);
            }
       }
       else
       {
           socket.end();
       }
    });

    function sendTest(client, index) {
        console.log("Sending test number: " + index);
        client.write("SOLVE " + tests[index] + "\n");
    }

    function sendBye(client) {
        client.write("BYE 33e87c9cfc6fbb5a57effa090404dd19\n");
        client.end();
    }
});

server.listen(55555);
@@ -172,23 +172,29 @@
  %5B%221
-+
+ + 
 1%22, %222
-+
+ + 
 2%22, %223
--
+ - 
 4%22, 
@@ -208,9 +208,11 @@
 , %229
-/
+ / 
 0%22%5D;
@@ -2097,8 +2097,9 @@
 (55555);
+%0A

Fix missing spaces in text