samedi 19 avril 2014

c# - appelant Asychronous Named Pipes instanciée en dot net de Java - Stack Overflow


This question is related to an earlier, more general question I asked on Java-C# communication, but I think it's probably specific enough to ask separately (let me know if you think I'm wrong - I haven't marked that one as answered yet and will come back to it once I figure out the solution that works best, this question is a step towards that..).


I'm trying to use named pipes to communicate between C# and Java. I'm basing my code on the example (pointed out by a responder to my previous question) at- http://v01ver-howto.blogspot.co.uk/2010/04/howto-use-named-pipes-to-communicate.html


The blog example works fine, but because in my own code I want to have a callback occur when my Java program connects to the C# instantiated pipe, I have to use an Asynchronous pipe (the example in the blog doesn't do this). So when instantiating the pipe, my code is-


 instructionPipe = new NamedPipeServerStream("InstructionPipe", PipeDirection.InOut, 4,PipeTransmissionMode.Byte,PipeOptions.Asynchronous);
instructionPipe.BeginWaitForConnection(new AsyncCallback(instructionPipeServerConnected), new Object());

..And then I write a callback called instructionPipeServerConnected that does the stuff I want on getting a connection.


On the Java side, again following the example in the blog, I set up the pipe on the Java side by writing-


    instructionPipeJava=new RandomAccessFile("\\\\.\\pipe\\" + "InstructionPipe","rw");

However, if I try to write some test data onto this pipe in Java-


   instructionPipeJava.write("This Is Test Text".getBytes());

And run the code, then the code stalls and can't get past this line. If I don't use an asynchronous pipe, then 'instructionPipeJava' will be able to write this text to the pipe just fine. However I need to use an async pipe to use callbacks on the c# side.


Does anyone have any suggestions? Perhaps the issue is that I am using 'new RandomAccessFile(..)' to create the pipe in Java and there is a more suitable way to do this to connect to an async C# pipe? Thank you for any advice you can offer!


Best, Chris



This question is related to an earlier, more general question I asked on Java-C# communication, but I think it's probably specific enough to ask separately (let me know if you think I'm wrong - I haven't marked that one as answered yet and will come back to it once I figure out the solution that works best, this question is a step towards that..).


I'm trying to use named pipes to communicate between C# and Java. I'm basing my code on the example (pointed out by a responder to my previous question) at- http://v01ver-howto.blogspot.co.uk/2010/04/howto-use-named-pipes-to-communicate.html


The blog example works fine, but because in my own code I want to have a callback occur when my Java program connects to the C# instantiated pipe, I have to use an Asynchronous pipe (the example in the blog doesn't do this). So when instantiating the pipe, my code is-


 instructionPipe = new NamedPipeServerStream("InstructionPipe", PipeDirection.InOut, 4,PipeTransmissionMode.Byte,PipeOptions.Asynchronous);
instructionPipe.BeginWaitForConnection(new AsyncCallback(instructionPipeServerConnected), new Object());

..And then I write a callback called instructionPipeServerConnected that does the stuff I want on getting a connection.


On the Java side, again following the example in the blog, I set up the pipe on the Java side by writing-


    instructionPipeJava=new RandomAccessFile("\\\\.\\pipe\\" + "InstructionPipe","rw");

However, if I try to write some test data onto this pipe in Java-


   instructionPipeJava.write("This Is Test Text".getBytes());

And run the code, then the code stalls and can't get past this line. If I don't use an asynchronous pipe, then 'instructionPipeJava' will be able to write this text to the pipe just fine. However I need to use an async pipe to use callbacks on the c# side.


Does anyone have any suggestions? Perhaps the issue is that I am using 'new RandomAccessFile(..)' to create the pipe in Java and there is a more suitable way to do this to connect to an async C# pipe? Thank you for any advice you can offer!


Best, Chris


0 commentaires:

Enregistrer un commentaire