Page 1 of 1
[Module] Named Pipe (Windows & MacOS)
Posted: Mon Apr 06, 2020 7:21 pm
by Thorsten1867
Named Pipe - Module (Windows & MacOS / 64Bit)
Exchange of messages between two programs using "named pipes
Code: Select all
; NamedPipe::GetFullName() ; Path and name of the pipe
; ----- Server -----
; NamedPipe::EventPipe() ; Returns the name of the pipe after #Event_Message
; NamedPipe::GetEventMessage() ; Querying the message after #Event_Message
; NamedPipe::Create() ; Creates a pipe with the name and starts a thread to read the pipe
; NamedPipe::Use() ; Use an existing pipe and starts a thread to read the pipe
; NamedPipe::Pause() ; Pause the thread to read the pipe
; NamedPipe::Resume() ; Resume the thread to read the pipe
; NamedPipe::Close() ; Close the pipe and exit the thread
; NamedPipe::SetMessageReply() ; Set a reply to the receipt of a message.
; ----- Client -----
; NamedPipe::SendMessage() ; Send a message (Return: Reply)
Download: NamedPipeModule.pbi
Re: [Module] Named Pipe (Windows)
Posted: Tue Apr 07, 2020 7:13 am
by infratec
Instead of the fixed Delay(100) I use always something like this:
Code: Select all
Thread\Exit = #True
If WaitThread(NamedPipe\Thread, 100) = 0
KillThread(NamedPipe\Thread)
EndIf
It has the possibity to be faster
But if you are in the Delay(1000) of the thread, you will always kill the thread.
Maybe the Delay(1000) is not a good idea.
And your code fails if I need more then one named pipe.
Until you implemented this, Create() should return a #False if there is already a pipe open.
Re: [Module] Named Pipe (Windows)
Posted: Tue Apr 07, 2020 11:26 am
by Fred
KillThread should never be used unless you can't quit the thread properly.
Re: [Module] Named Pipe (Windows)
Posted: Tue Apr 07, 2020 1:07 pm
by mk-soft
Fred wrote:KillThread should never be used unless you can't quit the thread properly.
Yes,
had only one case where KillThread needed to perform.
Was an external DCOM server that had deleted its resources without confirmation, and thus the interface call ran into nirvana.
Re: [Module] Named Pipe (Windows)
Posted: Tue Apr 07, 2020 2:05 pm
by infratec
I also noticed that a blocking mode is used.
So if no client connect, you have to kill the thread, because it never reaches the end of the loop.
Re: [Module] Named Pipe (Windows)
Posted: Tue Apr 07, 2020 3:38 pm
by mk-soft
At that time I had solved this problem by building a connect on the own handle and thus get out of the wait of "ConnectNamedPipe".
Re: [Module] Named Pipe (Windows)
Posted: Tue Apr 07, 2020 7:40 pm
by Thorsten1867
Update: Multiple pipe support
Re: [Module] Named Pipe (Windows)
Posted: Wed Apr 08, 2020 10:41 am
by Thorsten1867
Update: Support for MacOS
Re: [Module] Named Pipe (Windows & MacOS)
Posted: Wed May 20, 2020 7:24 am
by tatanas
I have tried your client/server example. If you pause the server then try a send from the client, it hangs for ever.
Can a timeout be implementing ?
Re: [Module] Named Pipe (Windows & MacOS)
Posted: Tue Oct 31, 2023 11:04 am
by Andre
I used this module in my project. It compiled fine...
After a long break I tried it again with PB 6.03 LTS (Win x64, ASM) and the use of the module via XIncludeFile causes an error now.
And I can't understand this error.... :-/
Just try:
1) If you compile the NamedPipeModule.pbi standalone it compiles fine and displays the window of the included example.
2) Now try to include the module in another source like this one (saved as NamedPipeModule_Test.pb for example):
Code: Select all
XIncludeFile "NamedPipeModule.pbi"
;#Server = 1
Debug "Test"
This will cause an "Integer constant expression expected for compiler directives." compiler error online line 614 now with PB6.03, no matter if ";#Server = 1" is commented or not (anyway this was only a try to workaround the error...).
But I don't understand, what the compiler want to tell me here!?
#Server = 1 is of course an integer number (used in the example included in the module too).
And why is the code in the "CompilerIf #PB_Compiler_IsMainFile ..... CompilerEndIf" section compiled, if I've only included the module in my test file?
I don't see the point and it looks a bit like a false compiler error/check introduced in the new PB version... any thoughts?
Re: [Module] Named Pipe (Windows & MacOS)
Posted: Tue Oct 31, 2023 11:30 am
by mk-soft
Should not have run through at all, as the file is no longer a MainFile as an include. Must be a bug.
Re: [Module] Named Pipe (Windows & MacOS)
Posted: Tue Oct 31, 2023 1:12 pm
by Andre
mk-soft wrote: Tue Oct 31, 2023 11:30 am
Should not have run through at all, as the file is no longer a MainFile as an include. Must be a bug.
Thanks for confirmation, I've done a bug-report here:
viewtopic.php?t=82778