Beruflich Dokumente
Kultur Dokumente
Windows
Internet Explorer
Office
Surface
Xbox
Skype
Windows Phone
More products
How to use named pipes for interprocess communication in Visual Basic .NET or in Visual Basic 2005
Article ID: 871044 - View products that this article applies to.
SUMMARY
This step-by-step article discusses how to use named pipes in Microsoft Visual Basic .NET or in Microsoft Visual Basic 2005 for interprocess communication. This article includes a code sample that demonstrates client/server communication by using a named pipe in Visual Basic .NET or in Visual Basic 2005. The article describes the interprocess communication by creating a named pipe server and a named pipe client. The communication over the pipe is performed in the following way: Create a named pipe. Block the server application by using the ConnectNamedPipe function until a client connects. Connect to the server by using the CallNamedPipe function. Call the ReadFile function or the WriteFile function to communicate over the pipe. Call the DisconnectNamedPipe function when the process finishes using the pipe. Call the CloseHandle function on the named pipe after you completed communicating over the pipe.
INTRODUCTION
A named pipe is a one-way or duplex pipe for communication between a pipe server and one or more pipe clients. You can user named pipes to provide communication between processes on the same computer or between processes on different computers across a network. The term "named pipe server" refers to a process that creates a named pipe, and the term "named pipe client" refers to a process that connects to an instance of a named pipe. You can use Microsoft Visual Basic .NET or Microsoft Visual Basic 2005 to create applications that communicate to other processes by using named pipes. This article contains a code sample that uses a named pipe to communicate between two Visual Basic .NET or Visual Basic 2005 Windows applications.
Requirements
This article assumes that you are familiar with the following topics: Windows applications Visual Basic .NET programming Using pipes The following list outlines the recommended hardware, software, network infrastructure, and service packs that you need: Microsoft Visual Studio .NET or Microsoft Visual Studio 2005 Microsoft .NET Framework
1. Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005. 2. On the File menu, point to New, and then click Project. 3. Under Project Types, click Visual Basic Projects, and then click Windows Application under Templates. Note In Visual Studio 2005, click Visual Basic under Project Types. In the Name box, type MyServerApp, and then click OK. By default, a form that is named Form1 is created. Add three Button controls to the Form1 form. On the View menu, click Properties Window. Set the Text property of the Button controls to the following values: Name Text
4. 5. 6. 7.
Button1 Create a named pipe Button2 Wait for the client connections Button3 Disconnect the server 8. Add a Label control to the Form1 form. The Label1 Label control is added to the Form1 form.
Design a Windows application that communicates with the named pipe server
To design a Visual Basic .NET or Visual Basic 2005 Windows application that is used to connect to the named pipe server, follow these steps: 1. Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005. 2. On the File menu, point to New, and then click Project. 3. Under Project Types, click Visual Basic Projects, and then click Windows Application under Templates. Note In Visual Studio 2005, click Visual Basic under Project Types. In the Name box, type MyClientApp, and then click OK. By default, a form that is named Form1 is created. Add a Button control to the Form1 form. Right-click Button1, and then click Properties. Set the Text property to Connect to the server. Add a Label control to the Form1 form. The Label1 Label control is added to Form1 form. Set the Visible property of Label1 Label control to False. Add two TextBox controls to the Form1 form.
4. 5. 6. 7. 8. 9. 10.
5. To disconnect the client application from the server, type 0 in the TextBox1 box in the client application, and then click Connect to the server. 6. Close the client application. 7. To disconnect the server end of the named pipe, and then close the server application, click Disconnect the server on the Form1 form of the server application.
REFERENCES
For more information, visit the following Microsoft Developer Network (MSDN) Web sites: Named pipes http://msdn2.microsoft.com/en-us/library/aa365590.aspx (http://msdn2.microsoft.com/en-us/library/aa365590.aspx) Transactions on named pipes http://msdn2.microsoft.com/en-us/library/aa365789.aspx (http://msdn2.microsoft.com/en-us/library/aa365789.aspx) Pipe functions http://msdn2.microsoft.com/en-us/library/aa365781.aspx (http://msdn2.microsoft.com/en-us/library/aa365781.aspx)
Properties
Article ID: 871044 - Last Review: January 11, 2007 - Revision: 2.4 APPLIE S TO
Microsoft Visual Basic 2005 Microsoft Visual Basic .NET 2003 Standard Edition Microsoft Visual Basic .NET 2002 Standard Edition
K eywo r d s : kbvs2005swept kbvs2005applies kbserver kbpipes kbipc kbclient kbhowtomaster kbhowto KB871044
Give Feedback
Back to the top