473,466 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Create 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.PipeName = ReferenceNames.PipeName;
if (!myNPipeServer.Running)
myNPipeServer.Start();

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

Create Client:

myNPipeClient = new Client();
myNPipeClient.PipeName = ReferenceNames.PipeName;
myNPipeClient.Connect();

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.
CreateServerWithCommonName();
CreateClientWithCommonName();
Assert.IsNotNull(myNPipeServer);
Assert.IsNotNull(myNPipeClient);
bool register = ServerListenedForClient(listenCount);
if (register)
Assert.IsNotNull(myNamedPipeServer.CurrentClient.m yHandle);
DisconnectClient();
DisconnectServer();
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
ServerListenedForClient 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_OVERLAPPED,
0,
255,
BUFFER_SIZE,
BUFFER_SIZE,
0,
IntPtr.Zero);

//could not create named pipe
if (myClientHandle.IsInvalid)
{
myConnectionStatus =
ReferenceNames.ConnectionStatus.ConnectionFailed;
myListenLoopCount = -1;
return;
}

int success = ConnectNamedPipe(myClientHandle,
IntPtr.Zero);

//could not connect client
if (success == 0)
{
myConnectionStatus =
ReferenceNames.ConnectionStatus.ConnectionFailed;
myListenLoopCount = -2;
return;
}

lock (myClient)
{
if (myClient == null)
myClient = new Client();
myClient.myHandle = myClientHandle;
myClient.myStream = new FileStream(myClientHandle,
FileAccess.ReadWrite, BUFFER_SIZE, true);
}
myListenLoopCount = (myListenLoopCount 10000) ? 0 :
myListenLoopCount+1;
}
Dec 10 '07 #1
0 1256

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

Similar topics

4
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
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:...
5
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...
4
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...
3
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....
0
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...
2
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...
0
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...
1
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()...
7
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
1
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...
0
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...
0
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,...
0
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...
0
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...
0
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...

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.