¿Qué tipo de datos se pueden enviar a través de un socket?

I am learning about Node.js for the first time, and came across the topic of using TCP to send data over a socket in Pedro Teixeira's Hands-On Node.js book.

require('net').createServer(function(socket) {
  // new connection
  socket.on('data', function(data) { 
    // got data
  socket.on('end', function(data) { 
    // connection closed
  socket.write('Some string');

I googled around for examples, and it seems that bytes, UTF-8 strings, etc can be sent over a socket. What I was curious about, and unable to find the answer to, was what sort of (if any) limits are there on sending data over a TCP socket (data-type, size, etc)?

preguntado el 27 de noviembre de 13 a las 06:11

1 Respuestas

TCP always provides a stream of bytes with no support for message boundaries. So anything that you can encode as a stream of bytes is fine, just remember that te lleve have to do that encoding in a way that the receiver can decode it.

respondido 27 nov., 13:06

So TCP always "streams" data just one byte at a time? - profesor meowingtons

No, it can stream the data in chunks of any size it wants. You put a stream of bytes in on one end and you get a stream of bytes out on the other. - David Schwartz

And, for stream readers/writers in Node, the pump/pipe functions help us deal with latency issues with streams? - profesor meowingtons

I'm not sure what you mean by "deal with latency issues". - David Schwartz

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.