473,800 Members | 2,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Callback on Named Pipe question

dgk
I trying to use a named pipe but can't figure out how to get the
callback to work:

Module Module1
Private ps As System.IO.Pipes .NamedPipeServe rStream
Public Sub main()
Application.Ena bleVisualStyles ()
Try
ps = New System.IO.Pipes .NamedPipeServe rStream("Test")
ps.BeginWaitFor Connection(Addr essOf HandleConnectio n, "Test")
Catch ex As Exception
' pipe already exists
End Try
Application.Run (Form1)
End Sub
Public Sub HandleConnectio n(ByVal ar As System.IAsyncRe sult)
ps.EndWaitForCo nnection(ar)
Using sr As New System.IO.Strea mReader(ps)
Dim message As String = ""
Do
message = sr.ReadLine
Console.WriteLi ne(message)
Loop While message IsNot Nothing
End Using
End Sub
End Module
I don't understand what the second parameter (object) is doing on the
BeginWaitForCon nection. Maybe because of that, and maybe not,
HandleConnectio n doesn't ever fire, even when another program does
open the pipe Test. Nor do I understand why I need to call
EndWaitForConne ction (maybe I don't need to?), or what to do with the
IAsyncResut.

Any info greatly appreciated.
Dec 27 '07 #1
1 5566
dgk
On Thu, 27 Dec 2007 10:41:34 -0500, dgk <dg*@somewhere. comwrote:
>I trying to use a named pipe but can't figure out how to get the
callback to work:

Module Module1
Private ps As System.IO.Pipes .NamedPipeServe rStream
Public Sub main()
Application.Ena bleVisualStyles ()
Try
ps = New System.IO.Pipes .NamedPipeServe rStream("Test")
ps.BeginWaitFor Connection(Addr essOf HandleConnectio n, "Test")
Catch ex As Exception
' pipe already exists
End Try
Application.Run (Form1)
End Sub
Public Sub HandleConnectio n(ByVal ar As System.IAsyncRe sult)
ps.EndWaitForCo nnection(ar)
Using sr As New System.IO.Strea mReader(ps)
Dim message As String = ""
Do
message = sr.ReadLine
Console.WriteLi ne(message)
Loop While message IsNot Nothing
End Using
End Sub
End Module
I don't understand what the second parameter (object) is doing on the
BeginWaitForCo nnection. Maybe because of that, and maybe not,
HandleConnecti on doesn't ever fire, even when another program does
open the pipe Test. Nor do I understand why I need to call
EndWaitForConn ection (maybe I don't need to?), or what to do with the
IAsyncResut.

Any info greatly appreciated.

Ok, I get to answer my own question. If you want to use async methods
with named pipes, you need to open the pipe as async:

ps = New System.IO.Pipes .NamedPipeServe rStream("Test",
IO.Pipes.PipeDi rection.InOut, 3,
IO.Pipes.PipeTr ansmissionMode. Message,
IO.Pipes.PipeOp tions.Asynchron ous)
Dec 27 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
7466
by: Rajarshi Guha | last post by:
Hi, I'm having a little trouble when I read from a named pipe. I create a pipe by os.mkfifo('/tmp/mypipe') and then open it for reading with fin = open('/tmp/mypipe','r+')
6
10764
by: Srijit Kumar Bhadra | last post by:
Hello, Here is an example of Multithreaded Pipe Server and Client using the excellent ctypes library (Windows). Reference - MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipc/base/multithreaded_pipe_server.asp and http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipc/base/named_pipe_client.asp Best Regards,
5
17426
by: richard | last post by:
I have a simple test to pass information from a client to a server using named pipe. what I really want is: when I type a line on the client, the server will output the line immediately. but to my surprise, I always have to terminate the client to get the server in action, i.e. prints out what I typed. anything I missed? I am compiling using gcc without any option. thanks, ---RICH
4
7662
by: Ken Allen | last post by:
Is there any built-in facility for handling named pipes in C#/.Net, or must one use unsafe code to access the WIN32 API directly? There exists some code that uses named pipes heavily and there exists a need for that code to send some information to a new .Net service I am writing. It is a relatively simple matter for the existing code to use a named pipe to send the data, but I can find no references to how I can create the named pipe...
3
2638
by: EricR | last post by:
I am trying to use .NET to "tap into" a named pipe created by a non .NET 3rd party application. Specifically, the application is a table loading utility. It opens a named pipe and waits for input. Does anybody know how I can write to the named pipe from a .NET program. I have tried using the traditional file access methods, and it appears that pipes have a problem with file streams. I have tried API calls, but since I do not have the...
0
1459
by: Nick | last post by:
hi,all I have a question about named pipe. How does the pipe server know the client closed the connection? We can refer the example for CreateNamedPipe() function in MSDN. In block mode, once ConnectNamedPipe() returns, it means the client called CreateFile(), and after finish reading and writing, client call CloseHandle(), at this point, how does the pipe server know the pipe has been closed? And if client did not call CloseHandle(),...
2
5067
by: FB's .NET Dev PC | last post by:
I am writing two services in VB.NET, one of which needs to send text strings to the other. After reading, I decided (perhaps incorrectly) that named pipes would be the best interprocess communication method for this task. I set about creating, on the pipe's server side, a new thread which would instantiate a blocking inbound message pipe, and the client side which would write to that pipe when needed. Being on the same PC, security is...
0
2915
by: olaf.dietsche | last post by:
Hi, The system is Windows XP and DB2 v8.1.7. I'm trying to load a text file via named pipe into a table. I have two programs: the first program creates the named pipe, waits for a client and writes the text file into the named pipe. the second program is doing the db2Load() call.
7
7657
by: andrewb | last post by:
Hi all, Having some trouble using named pipes and Visual Basic .NET and would appreciate and help you could offer. Essentially I am trying to develop a simple client/server application that exchanges text messages using named pipes. The internet resources seem a bit scarce and the only Microsoft resource I can find is http://support.microsoft.com/kb/871044.
0
10505
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10276
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10035
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9090
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6813
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.