Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在DELPHI XE2中创建的控制台应用程序中,从nodejs中创建的IPC服务器接收回消息_Node.js_Delphi_Ipc_Named Pipes - Fatal编程技术网

Node.js 在DELPHI XE2中创建的控制台应用程序中,从nodejs中创建的IPC服务器接收回消息

Node.js 在DELPHI XE2中创建的控制台应用程序中,从nodejs中创建的IPC服务器接收回消息,node.js,delphi,ipc,named-pipes,Node.js,Delphi,Ipc,Named Pipes,因此,我有一个运行IPC服务器的nodejs应用程序,我想通过delphi应用程序与之通信。 到目前为止,我可以将消息从delphi应用程序发送到nodejs服务器,它工作正常,但当我尝试响应delphi客户端时,它不工作! delphi部分使用Russell Libby的著名IPC库,不幸的是,web上没有太多关于IPC和delphi的教程 以下是delphi代码: program CmdClient; {$APPTYPE CONSOLE} uses Windows, Messages,

因此,我有一个运行IPC服务器的nodejs应用程序,我想通过delphi应用程序与之通信。 到目前为止,我可以将消息从delphi应用程序发送到nodejs服务器,它工作正常,但当我尝试响应delphi客户端时,它不工作! delphi部分使用Russell Libby的著名IPC库,不幸的是,web上没有太多关于IPC和delphi的教程

以下是delphi代码:

program CmdClient;
{$APPTYPE CONSOLE}

uses
  Windows, Messages, SysUtils, Pipes;

type
  TPipeEventHandler =  class(TObject)
  public
     procedure  OnPipeSent(Sender: TObject; Pipe: HPIPE; Size: DWORD);
  end;

procedure TPipeEventHandler.OnPipeSent(Sender: TObject; Pipe: HPIPE; Size: DWORD);
begin
  WriteLn('On Pipe Sent has executed!');
end;

var
  lpMsg:         TMsg;
  WideChars:     Array [0..255] of WideChar;
  myString:      String;
  iLength:       Integer;
  pcHandler:     TPipeClient;
  peHandler:     TPipeEventHandler;

begin

  // Create message queue for application
  PeekMessage(lpMsg, 0, WM_USER, WM_USER, PM_NOREMOVE);

  // Create client pipe handler
  pcHandler:=TPipeClient.CreateUnowned;
  // Resource protection
  try
     // Create event handler
     peHandler:=TPipeEventHandler.Create;
     // Resource protection
     try
        // Setup clien pipe
        pcHandler.PipeName:='autoreg';
        pcHandler.ServerName:='.';
        pcHandler.OnPipeSent:=peHandler.OnPipeSent;
        // Resource protection
        try
           // Connect
           if pcHandler.Connect(5000) then
           begin
              // Dispatch messages for pipe client
              while PeekMessage(lpMsg, 0, 0, 0, PM_REMOVE) do DispatchMessage(lpMsg);
              // Setup for send
              myString:='the message I am sending';
              iLength:=Length(myString) + 1;
              StringToWideChar(myString, wideChars, iLength);
              // Send pipe message
              if pcHandler.Write(wideChars, iLength * 2) then
              begin
                 // Flush the pipe buffers
                 pcHandler.FlushPipeBuffers;
                 // Get the message
                 if GetMessage(lpMsg, pcHandler.WindowHandle, 0, 0) then DispatchMessage(lpMsg);
              end;
           end
           else
              // Failed to connect
              WriteLn('Failed to connect to ', pcHandler.PipeName);
        finally
           // Show complete
           Write('Complete...');
           // Delay
           ReadLn;
        end;
     finally
        // Disconnect event handler
        pcHandler.OnPipeSent:=nil;
        // Free event handler
        peHandler.Free;
     end;
  finally
     // Free pipe client
     pcHandler.Free;
  end;

end.
现在,nodejs代码:

require('./loggerConfig')();

const net = require('net');
const path = require('path');

const server = net.createServer(socket => {

  socket.on('end', () => {
    console.log('client disconnected');
  });

  socket.on('data', data => {
      console.log('socket data event!');
      console.log(data.toString());

    socket.write('hello\r\n');
    socket.pipe(socket);    
  })

  socket.on('error', (error) => {
    console.log(error.message);
  });  

  socket.on('drain', () => {
    console.log('drained!');
  })
})

server.on('close', function (event) {
    console.log('server closed!')
}) 

server.on('connection', function (event) {
    console.log('server connection event!');
})

server.on('error', function (error) {
    console.log(error.message);
})

server.on('listening', function (event) {
    console.log('server is listening!')
})


server.listen({
    path: path.join('\\\\?\\pipe\\', 'autoreg'),
    readableAll: true,
    writableAll: true    
});

thx

我写了一篇关于Russel Liby代码的博客文章。它已经很老了,但应该仍然有效。也许你可以在那里找到帮助:thx,我来看看@fpietteI写了一篇关于Russel Liby代码的博客文章。它已经很老了,但应该仍然有效。也许你可以在那里找到帮助:thx,我会看看@fpiette