C# create pipe client. Tested on Oracle VirtualBox and Visual Studio 2010.
/* | |
Create a Serial Port on VirtualBox and "Host Pipe" set its Port mode. After that check "Create Pipe" checkbox. | |
Then, "\\.\pipe\TestPipe" write on input of Port/File Path. After that, run your server code. | |
I wrote a little server code n C#. I found on internet something. | |
http://www.codeproject.com/Tips/492231/Csharp-Async-Named-Pipes | |
http://www.codeproject.com/Tips/441841/Csharp-Named-Pipes-with-Async | |
http://stackoverflow.com/questions/244367/c-sharp-3-5-connecting-named-pipe-across-network | |
etc. My client code is following. | |
*/ | |
private void readButton_Click(object sender, EventArgs e) | |
{ | |
NamedPipeServerStream pipeServer = new NamedPipeServerStream( | |
"TestPipe", | |
PipeDirection.InOut, | |
10, | |
PipeTransmissionMode.Byte, | |
PipeOptions.None | |
); | |
pipeServer.WaitForConnection(); | |
listBox1.Items.Add(pipeServer.ReadByte()); | |
} | |
private void writeButton_Click(object sender, EventArgs e) | |
{ | |
NamedPipeClientStream pipeClient = new NamedPipeClientStream( | |
".", | |
"TestPipe", | |
PipeDirection.InOut); | |
pipeClient.Connect(); | |
byte[] data = new byte[10]; | |
data[0] = 0x10; | |
data[1] = 0x10; | |
data[2] = 0x10; | |
data[3] = 0x10; | |
data[4] = 0x10; | |
data[5] = 0x10; | |
data[6] = 0x10; | |
data[7] = 0x10; | |
data[8] = 0x10; | |
data[9] = 0x10; | |
pipeClient.Write(data, 0, 9); | |
pipeClient.Close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment