Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

386
Visualizações
Why is Net.Socket.Write() not sending the full string to my TCP client?

EDIT: Im desperate to get this thing done so I can move onto a new project, heres the source: https://github.com/eanlockwood/TalkmonClient

Everything else works fine. The server is well aware of the usernames associated with the clients and it sends information to them accordingly, but the weird thing is the string cuts off after the first variable. Here is the loop for a typical send message:

function SendMessage(msg, client)
{

    const clientName = ClientNames.get(client);
    let recieverMsg = `${clientName}: ${msg}`;

    console.log(recieverMsg);


    Clients.forEach(elm => {
        if(elm != client)
        {
            elm.write(recieverMsg);
        }
        else {
            elm.write("You: " + msg);
        }
    })

}

msg is the chunk.toString() in the socket.on('data') event, again, node picks up what this string means, it debugs fine but in the client (imagine the windows cmd) itll just print the username and go to the next line.

The loop for the client side is pretty simple too,

char buff[4090];

do
    {
        ZeroMemory(buff, 4090);
        int messageRevieved = recv(sock, buff, 4090, 0);

        if (messageRevieved > 0)
        {
            userInput->FreezeInput();
            cout << buff << endl;
            userInput->UnFreezeInput();
        }

    } while (0 == 0);

User input is handled in its own class on a seperate thread, again, working just fine.

I think it has to do with a misunderstanding of what socket.write and recv actually do or maybe I just dont understand javascript strings enough. Either way this problem is annoying because its the last step in creating my app

Ive done some extensive tests too, it really just doesnt like the concat strings. Itll print everything up until the first variable, meaning I could have socket.write("hehehehehehe " + variable1 + " kadjgkdgad"); and it would print hehehehehe [variable1 value] and just stop

Tl;dr: The server will write to the sockets up to the first variable in a concat'd string and then stop, its so weird.

EDIT: The dependencies used serverside are Net and dotnet if that makes a difference.

EDIT 2: I found another issue. After sending a few messages the client who sent the messages will stop printing the "you: " part and will only print the message, it will do this server side too but its weird because the receiving clients will still print out who the message is from.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda