473,591 Members | 2,871 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Named pipe question!

Hi All,

I am trying to create a named pipe for two of my process to
communicate. I wrote bunch of unit test to make sure the
funcationality works the way it is supposed to be. In this app I am
trying to broadcast message from server to client (only one client
will be available at any time) and if the client is registered it see
the message. If the client is not registered they need to be bothered.
Before I ask my questions here is the code snippets

Create Server:

myNPipeServer = new Server();
myNPipeServer.P ipeName = ReferenceNames. PipeName;
if (!myNPipeServer .Running)
myNPipeServer.S tart();

Above code basically starts a seperate thread to do the listening of
client registration request.

Create Client:

myNPipeClient = new Client();
myNPipeClient.P ipeName = ReferenceNames. PipeName;
myNPipeClient.C onnect();

Above code simply sits and listen to any message coming from server.

I have around 12 test cases (NUnit) I trying to run and I am running
into a problem of inconsistant behaviour. Sometimes server picks up
the client registration and sometime server never sees client
registration. Sometimes all 12 cases runs fine, sometime couple and
some times none completes. This is very limited information but if you
need any additional information, please ask me and I will add them to
the thread. Here is one sample test case that exhibit the protean
behaviour.
CreateServerWit hCommonName();
CreateClientWit hCommonName();
Assert.IsNotNul l(myNPipeServer );
Assert.IsNotNul l(myNPipeClient );
bool register = ServerListenedF orClient(listen Count);
if (register)
Assert.IsNotNul l(myNamedPipeSe rver.CurrentCli ent.myHandle);
DisconnectClien t();
DisconnectServe r();
if (!register) Assert.IsFalse( true);

Before I register I get a counter value from server, when client
registration runs the same counter is increased by one value. The
ServerListenedF orClient method basically verifies the count changed
for a minute with 5 second increment to make sure the test case to
give server enough time to register the client. Sometimes the count
never changes thats how I know the client registration never took
place. If you are interested in the server side listen code here it
is,

Server Listening thread:

while (true)
{
myClientHandle = CreateNamedPipe (
this.myPipeName ,
DUPLEX | FILE_FLAG_OVERL APPED,
0,
255,
BUFFER_SIZE,
BUFFER_SIZE,
0,
IntPtr.Zero);

//could not create named pipe
if (myClientHandle .IsInvalid)
{
myConnectionSta tus =
ReferenceNames. ConnectionStatu s.ConnectionFai led;
myListenLoopCou nt = -1;
return;
}

int success = ConnectNamedPip e(myClientHandl e,
IntPtr.Zero);

//could not connect client
if (success == 0)
{
myConnectionSta tus =
ReferenceNames. ConnectionStatu s.ConnectionFai led;
myListenLoopCou nt = -2;
return;
}

lock (myClient)
{
if (myClient == null)
myClient = new Client();
myClient.myHand le = myClientHandle;
myClient.myStre am = new FileStream(myCl ientHandle,
FileAccess.Read Write, BUFFER_SIZE, true);
}
myListenLoopCou nt = (myListenLoopCo unt 10000) ? 0 :
myListenLoopCou nt+1;
}
Dec 10 '07 #1
0 1264

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

Similar topics

4
7456
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
10738
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
17410
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
7649
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
2631
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
1419
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
5052
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
2894
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.
1
5531
by: dgk | last post by:
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.NamedPipeServerStream Public Sub main() Application.EnableVisualStyles() Try ps = New System.IO.Pipes.NamedPipeServerStream("Test") ps.BeginWaitForConnection(AddressOf HandleConnection, "Test")
7
7620
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
7870
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8362
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
7992
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
8225
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...
1
5732
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5400
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
3850
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1465
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1199
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.