i'm developing test application communicate between 2 processes using anonymous pipes. can send message clientview serverview can't other way round since pipe connection throws exceptions.
servercode
public class pipeserverhandler { private static anonymouspipeserverstream serversenderstream; private static anonymouspipeserverstream serverreceiverstream; private static streamwriter sw; private static streamreader sr; public void serverstart() { serversenderstream = new anonymouspipeserverstream(pipedirection.out, handleinheritability.inheritable); serverreceiverstream = new anonymouspipeserverstream(pipedirection.in, handleinheritability.inheritable); string senderid = serversenderstream.getclienthandleasstring(); string receiverid = serverreceiverstream.getclienthandleasstring(); processstartinfo process = new processstartinfo(@"c:\users\vinushap\documents\visual studio 2015\projects\communicationproject\clientview\bin\debug\clientview.exe", senderid + "_" + receiverid); process.useshellexecute = false; process clientprocess = process.start(process); serversenderstream.disposelocalcopyofclienthandle(); sr = new streamreader(serverreceiverstream); } public string readdata() { string temp; temp = sr.readline(); return temp; } }
client code
public class pipeclienthandler { private static anonymouspipeclientstream clientreceiverstream; private static anonymouspipeclientstream clientsenderstream; private static streamreader sr; private static streamwriter sw; public void clientstart(string[] args) { string[] id = args[0].split('_'); string senderid = id[0]; string receiverid = id[1]; clientreceiverstream = new anonymouspipeclientstream(pipedirection.in, senderid); clientsenderstream = new anonymouspipeclientstream(pipedirection.out, receiverid); sw = new streamwriter(clientsenderstream); sw.autoflush = true; } public void writestream(string data) { sw.writeline(data); clientsenderstream.waitforpipedrain(); } }
this app.xaml.cs class captures command line args
private void application_startup(object sender, startupeventargs e) { pipeclienthandler handler = new pipeclienthandler(); if (e.args.length > 0) { handler.clientstart(e.args); } }
when sending data pipeserverhandler pipeclienhandler works well, when send data pipeclienthandler pipeserverhandler doesn't show me messages.
clientsenderstream error
i know bit old, anonymous pipes 1 way. you'll need 2 anonymous pipes 2 way communications.
Comments
Post a Comment