1

As I see Node JS can't send string to client.
When I use socket.write("string") client doesn't receive anything. socket.write(new Buffer("string")) — same situation.

var b = new Buffer(15);
b.write("string");
socket.write(b);

It looks like something works, but client receives string along with a lot of blank space.

var b = new Buffer(6); //6 - lenght of string in bytes
b.write("string");
socket.write(b);

Again nothing!

var b = new Buffer(7);
b.write("string");
socket.write(b);

Now there's less blank characters.
My head really hurts. Is it really complicated to send simple string?
Waiting for my savior :)

2 Answers 2

2

socket.write("string") actually works fine. Check the docs.

Sign up to request clarification or add additional context in comments.

Comments

-1

You forgot to end the transmission, after each write do a socket.end();

Also, if you're only sending one string you can always do a socket.end(stringToSend);

Please also refer to NodeJS documentation of the modul 'net'.

2 Comments

Huh? Why end? I'm developing browser MMO. So every sent message should disconnect user from server?
when you do a socket.end(), it ends the current message, doesn't disconnect the socket, it just tells the client-side that the message being sent in that section is the last one in that batch.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.