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

后端 未结 3 1144
一整个雨季
一整个雨季 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:05

    The method you're looking for is net.createConnection(path):

    var client = net.createConnection("/tmp/mysocket");
    
    client.on("connect", function() {
        ... do something when you connect ...
    });
    
    client.on("data", function(data) {
        ... do stuff with the data ...
    });
    

提交回复
热议问题