使用Node IPC Namedpipe和Vb6 CallNamedPipe客户端

时间:2017-06-24 22:44:56

标签: node.js vb6 ipc

问题:节点IPC服务器没有从vb客户端读取任何数据。虽然我可以看到日志“Client Connected”,但数据不会在任何时候触发,因此连接结束并立即关闭。

输出我看到了:

output sample

VB客户端代码:

    Dim strLen As Integer
    Dim rcvArray() As Byte, sndArray() As Byte, rcvStr As String
    Dim inBufBytes As Long, outBufBytes As Long, bytesRead As Long
    Dim i As Integer, Res As Long

    Dim sndStr As String
    sndStr = "Test Message"

    strLen = Len(sndStr)
    ReDim sndArray(5000)
    For i = 0 To strLen - 1
        sndArray(i) = Asc(Mid(sndStr, i + 1, 1))
    Next i

    ReDim rcvArray(5050)
    inBufBytes = 5000
    outBufBytes = 5050

    'Expecting Aero to send back an xml string with Bundles details
    Res = CallNamedPipe("\\.\pipe\MyPipe", sndArray(0), strLen,
                          rcvArray(0), outBufBytes,
                          bytesRead, 30000)
    'Wait up to 30 seconds for a response
    'Format the data received, and then display the data in the text box
    If Res > 0 Then
        rcvStr = StrConv(rcvArray, vbUnicode)
        TextBox2.Text = rcvStr
    End If

NodeJS代码:

let net = require('net'),
    pipeName = '\\\\.\\pipe\\MyPipe',
    server = null;

server = net.createServer( (socket) => {
    console.log("-- Client Connected --\r\n");

    socket.on('data', (chunk) => {
        console.log(`Received ${chunk.length} bytes from ContainerPipe: ${chunk} \r\n`);
    });

    socket.on('end', () => {
        console.log("** End Client **\r\n");
    });

    socket.on('close', () => {
        console.log("** Close Client **\r\n");
    });

    socket.on('error', (err) => {
        console.log("** Error: %s \r\n", err.message);
    });
});

server.listen(pipeName, () => {
    console.log("\r\n== Server Listening ==\r\n");
});

1 个答案:

答案 0 :(得分:0)

代替使用

CallNamedPipe

我的解决方案是使用

CreateFile
WriteFile