Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

388
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!