Search code examples
node.jsunix-socketnode-ipc

node-ipc error "Messages are large, You may want to consider smaller messages."


So I am trying to setup a socket server in node.js using node-ipc, then send data from a client. I can connect perfectly fine, however when I send data I recieve the error Messages are large, You may want to consider smaller messages. I have followed all advice here, however, have still been unsuccessful in resolving the problem. I have tried sending from a socket connection in C and also from terminal. Any advice would be great, thanks in advance.

main.js

const ipc = require("node-ipc");
const socket = '/tmp/edufuse.sock';
ipc.serve(
    socket,
    function(){
      ipc.server.on(
          'myEvent',
          function(data){
            ipc.log('got a message : '.debug, data);
          }
      );
    }
);
ipc.server.start();

test.json
```json
{ type: message, data: { foo: bar } }

command from terminal

pr -tF test.json | nc -U /tmp/edufuse.sock

Solution

  • Unfortunately, it appears this is an underlying problem with node-ipc. In order to get around this, I used net sockets and TCP.

    const net = require('net');
    const port = 8080;
    const host = '127.0.0.1';
    
    var server = net.createServer(function(socket) {
      socket.on('data', function(data){
        let str = data.toString('utf8');
        console.log(str);
        try {
          let json = JSON.parse(str);
          console.log(json);
        } catch (e) {
          console.log('error str: ' + str);
        }
    
      });
      socket.on('error', function(err) {
        console.log(err)
      })
    });
    
    server.listen(port, host);