Connecting to an already established UNIX socket with node.js?

后端 未结 3 1143
一整个雨季
一整个雨季 2021-01-02 04:33

I am working on a node.js application that will connect to a UNIX socket (on a Linux machine) and facilitate communication between a web page and that socket. So far, I have

3条回答
  •  心在旅途
    2021-01-02 05:13

    I was just trying to get this to work with Linux's abstract sockets and found them to be incompatible with node's net library. Instead, the following code can be used with the abstract-socket library:

    const abstract_socket = require('abstract-socket');
    
    let client = abstract_socket.connect('\0my_abstract_socket');
    
    client.on("connect", function() {
        ... do something when you connect ...
    });
    
    client.on("data", function(data) {
        ... do stuff with the data ...
    });
    

提交回复
热议问题