Skip to Main Content
C# Cookbook, 2nd Edition
book

C# Cookbook, 2nd Edition

by Jay Hilyard, Stephen Teilhet
January 2006
Intermediate to advanced content levelIntermediate to advanced
1184 pages
43h 23m
English
O'Reilly Media, Inc.
Content preview from C# Cookbook, 2nd Edition
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
906
|
Chapter 16: Networking
class NamedPipeClientConsole
{
static void Main(string[] args)
{
// Client test code - commented out as it should go in a separate
// console test app
// Create our pipe client.
NamedPipeClient _pc =
new NamedPipeClient("\\\\.\\PIPE\\mypipe");
if (_pc != null)
{
using (_pc)
{
// Connect to the server.
_pc.Connect( );
// Set up a dummy message.
string testString = "This is my message!";
// Turn it into a byte array.
byte[] writebuffer = Encoding.Unicode.GetBytes(testString);
uint len = Convert.ToUInt32(writebuffer.Length);
// Write the message ten times.
for (int i = 0; i < 10; i++)
{
MemoryStream response = _pc.WriteMessage(writebuffer, len);
if (response == null)
{
Debug.Assert(false,
"Failed to write message!");
}
else
{
WriteMessageResponse(response);
}
}
}
}
Console.WriteLine("Press Enter to exit...");
Console.ReadLine( );
}
static void WriteMessageResponse(MemoryStream responseStream)
{
string response =
Encoding.Unicode.GetString(responseStream.ToArray( ));
Console.WriteLine("Received response: {0}", response);
}
}
}
Example 16-6. Using the NamedPipeClient class (continued)
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# Cookbook

C# Cookbook

Joe Mayo
C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard
Head First C#, 4th Edition

Head First C#, 4th Edition

Andrew Stellman, Jennifer Greene

Publisher Resources

ISBN: 0596100639Supplemental ContentCatalog PageErrata