Unable to resolve error for task17 with csharp

I’m stuck on .
public static void BroadcastMessage(string message)
{
Console.WriteLine("Broadcasting " + message);
SemaphoreSlimm.Wait();
var fistMessage = “*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\n123\r\n”;
var secondMessage = “*3\r\n$3\r\nSET\r\n$3\r\nbar\r\n$3\r\n456\r\n”;
string toSend = secondMessage;
if (fisrMethod)
{
toSend = fistMessage;
fisrMethod = false;
}

    foreach (Socket connectedSlave in ConnectedSlaves)
    {
        Console.WriteLine("sending" + message);
        Console.WriteLine(ConnectedSlaves.Count);
        Console.WriteLine(connectedSlave.Connected);
        Console.WriteLine(connectedSlave.Blocking);
        connectedSlave.Send(Encoding.UTF8.GetBytes(message));
    }

    SemaphoreSlimm.Release();

}

Here are my logs:
m] sending*3
[your_program] $3
[your_program] SET
[your_program] $3
[your_program] foo
[your_program] $3
[your_program] 123
[your_program]
[your_program] 1
[your_program] True
[your_program] True
[tester::#ZN8] client: Received bytes: “+OK\r\n”
[tester::#ZN8] client: Received RESP value: “OK”
[tester::#ZN8] Received “OK”
[tester::#ZN8] client: $ redis-cli SET bar 456
[tester::#ZN8] client: Sent bytes: “*3\r\n$3\r\nSET\r\n$3\r\nbar\r\n$3\r\n456\r\n”
[your_program] received new message *3
[your_program] $3
[your_program] SET
[your_program] $3
[your_program] bar
[your_program] $3
[your_program] 456
[tester::#ZN8] client: Received bytes: “+OK\r\n”
[tester::#ZN8] client: Received RESP value: “OK”
[your_program]
[your_program] royte message called
[your_program] System.String
[your_program] got command set
[your_program] False
[your_program] Broadcasting *3
[your_program] $3
[your_program] SET
[your_program] $3
[your_program] bar
[your_program] $3
[your_program] 456
[tester::#ZN8] Received “OK”
[tester::#ZN8] client: $ redis-cli SET baz 789
[tester::#ZN8] client: Sent bytes: "3\r\n$3\r\nSET\r\n$3\r\nbaz\r\n$3\r\n789\r\n"
[your_program]
[your_program] sending
3
[your_program] $3
[your_program] SET
[your_program] $3
[your_program] bar
[your_program] $3
[your_program] 456
[your_program]
[your_program] 1
[your_program] True
[your_program] True
[your_program] received new message *3
[your_program] $3
[your_program] SET
[your_program] $3
[your_program] baz
[your_program] $3
[your_program] 789
[your_program]
[your_program] royte message called
[your_program] System.String
[your_program] got command set
[your_program] False
[your_program] Broadcasting 3
[your_program] $3
[your_program] SET
[your_program] $3
[your_program] baz
[your_program] $3
[your_program] 789
[your_program]
[your_program] sending
3
[your_program] $3
[your_program] SET
[your_program] $3
[your_program] baz
[your_program] $3
[your_program] 789
[your_program]
[your_program] 1
[your_program] True
[your_program] True
[tester::#ZN8] client: Received bytes: “+OK\r\n”
[tester::#ZN8] client: Received RESP value: “OK”
[tester::#ZN8] Received “OK”
[tester::#ZN8] Sent 3 SET commands to master successfully.
[tester::#ZN8] replica: Expecting “SET foo 123” to be propagated
[tester::#ZN8] replica: Received bytes: “*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\n123\r\n”
[tester::#ZN8] replica: Received RESP value: [“SET”, “foo”, “123”]
[tester::#ZN8] Received [“SET”, “foo”, “123”]
[tester::#ZN8] replica: Expecting “SET bar 456” to be propagated
[tester::#ZN8] Received: “\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00”
[tester::#ZN8] ^ error
[tester::#ZN8] Error: “\x00” is not a valid start of a RESP2 value (expected +, -, :, $ or *)
[tester::#ZN8] Test failed
[tester::#ZN8] Terminating program
[your_program] received new message *3
[your_program] $3
[your_program] SET
[your_program] $3
[your_program] baz
[your_program] $3
[your_program] 789
[your_program]
[your_program] royte message called
[your_program] System.String
[your_program] got command set
[your_program] False
[tester::#ZN8] Program terminated successfully

the weird thing i cant wrap my head around is that when i do send the firstMessage variable and then the secondMessage variable instead of the parameter string, it works. It sends the right message and i get a green response. The first message works with Received [“SET”, “foo”, “123”] but the second one i get this Received: “\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00” when not setting the message manually . Any help is appreciated thanks.

Ok i was able to solve it on my own. For everyone wondering
int amountBytesReceived = await client.ReceiveAsync(buffer);
var newbuff = new ArraySegment(buffer, 0, amountBytesReceived);
var got = Encoding.UTF8.GetString(newbuff);

what solved it was creatin the newbuff with the exact length of the string. Apparently the string i wanted to send at the end was still 1024 bytes(sizes of the buffer) long and that seemed to have messes up everything. basically i encoded the buffer to a string and then tried to send that string via Encoding.UTF8.GetBytes(message). probably there were some bytes saved from a message before that was longer but really dont know for sure as it printed out exactly what i wanted before sending it.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.