A
A
AlexSam2012-11-15 11:55:06
Computer networks
AlexSam, 2012-11-15 11:55:06

Does the data from the server not always reach the NodeJS client?

The problem is this: there is a server written on a node. The server opens a TCP socket: port and starts listening to it (I emphasize - not HTTP, a regular TCP socket). Clients (flash) connect to this socket and listen to something. The specifics of the server operation is such that clients send practically nothing to it, and only the server sends it. The client sends only an authorization command upon connection. The server sends commands to the client, if necessary. So, quite often, in about 10% of cases, data from the server does not reach the client. Moreover, the dependence cannot be determined. Sometimes it may happen that immediately after authorization the data does not reach, sometimes after a certain period of time. Moreover, the connection does not disappear and the next time the data is sent, everything comes up normally.
So here are the questions:
- what to do to be guaranteed to be sure that the data reaches?
- if the first is not possible, then how to track on the server that the data has reached the client without resorting to echo responses from the client?
- what is the socket.pipe(socket) method in the example on the main nodejs.org site? I did not find it in the dock, but maybe it will somehow help.

If someone has come across a similar situation or knows the work of the NET package ( nodejs.org/api/net.html ) well, help solve the problem.

Ps The DEV server is not loaded at all. Developers only. They blamed it on network lags, but 10% of cases is too much, given that pings go normally.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
P
PomanoB, 2012-11-15
@PomanoB

The TCP protocol guarantees the delivery of data, it seems to me that the problem is in your application layer protocol.
The pipe() method is described here - nodejs.org/api/stream.html#stream_stream_pipe_destination_options
In short: it connects the read stream of the given socket with the write stream passed as a parameter. That is, everything that came to this socket will be written to the stream passed as a parameter, in this case, the same socket. Thus, an echo server is obtained.

C
cat_crash, 2012-11-15
@cat_crash

Have you tried to trace with the same tcpdump (wireshark) - whether the packets are leaving the server. Do you receive delivery confirmations?

S
Stdit, 2012-11-15
@Stdit

This may be due to the socket stream being handled incorrectly (most likely on the client) because you are not using carrier or other buffering/division. The data event does not mean that it contains exactly the string sent by the second party. There may be a part of it, or there may be several lines at once (depending on the size of the data and the size of the transfer buffer). Thus, data can be lost if, for example, two server commands fall into the same "data" event, failing packet recognition (on the client, in particular, depending on the implementation). I stepped on this stone, the solution is carrier , some socket framework or my own version of the top-level protocol. Here is an example of demonstrating tests:

Hidden text
// server.js
var net = require('net');
var server = new net.Server();

process.on('uncaughtException', function (err) {
    console.log(err.stack);
});

server.listen(12345);
server.on('connection', function (connection) {
    console.log('connection');
    connection.on('data', function (data) {
        console.log('server data', data.toString());
        connection.write(data);
    });
    connection.on('end', function () {
        console.log('server end');
    });
});

// client.js
var net = require('net');
var client = new net.Socket();

process.on('uncaughtException', function (err) {
    console.log(err.stack);
});

client.connect(12345);
client.on('connect', function (connection) {
    console.log('connect');
    client.on('data', function (data) {
        console.log('client data', data.toString());
    });
    client.on('end', function () {
        console.log('client end');
    });
});

setTimeout(function () {
    "use strict";
    client.write('string1');
    client.write('string2');
}, 100);

setTimeout(function () {
    "use strict";
    var i = 100000;
    var string = '';
    while (i--) {
        string += i;
    }
    client.write(string);
}, 200);

setTimeout(function () {
    "use strict";
    client.write('string3');
    client.end('string4');
}, 300);


If my assumption is wrong and you took care of it, then you need to do a tcpdump with a port filter, and see what comes and goes where.

K
Keenest, 2012-11-16
@Keenest

As an option, try to add at least one non-flash client, and draw conclusions (regarding the localization of the problem) depending on whether it receives all messages.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question