进程通信常见的进程通信方式有:管道(Pipe)命名管道信号消息队列其他管道都是比较简单基础的技术,看一看吧。NodeIPC支持Node官方文档中的Net模块:IPCSupportnet模块在Windows上支持IPCwithnamedpipes,在其他操作系统上支持UNIXdomainsockets。类:net.ServerAddedin:v0.1.90该类用于创建TCP或IPC服务器。如您所见,Node可以使用命名管道在Windows上进行进程通信。测试C#publicpartialclassfrmMain:Form{publicfrmMain(){InitializeComponent();}privateconststringPIPE_NAME="hahaha_pipe";privatevoidbtnStartListen_Click(objectsender,EventArgse){Task.Factory.StartNew(StartListen);}privatevoidStartListen(){for(;;){using(NamedPipeServerStreampipeServer=newNamedPipeServerStream(PIPE_NAME,PipeDirection.InOut,1)){try{pipeServer.WaitForConnection();pipeServer.ReadMode=PipeTransmissionMode.Byte;使用(StreamReadersr=newStreamReader(pipeServer)){stringmessage=sr.ReadToEnd();txtMessage.Invoke(newEventHandler(delegate{txtMessage.AppendText(message+"\n");}));}}catch(IOExceptionex){MessageBox.Show("无法监控管道:"+ex.Message);}}}}}设计界面很简单:Nodejsconstnet=require('net');constPIPE_NAME="hahaha_pipe";constPIPE_PATH="\\\\.\\pipe\\"+PIPE_NAME;letl=console.log;constclient=net.createConnection(PIPE_PATH,()=>{//'connect'listenerl('连接到服务器!');client.write('world!\r\n');client.end();});client.on('end',()=>{l('与服务器断开连接');});代码很简单,创建连接,然后发送数据,测试效果总结,多看文档^_^C\#代码下载
