473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to write named pipes application

20
am a newby with Windows named pipes, and have an obviously newby question.

The context of the program is this: I am trying to create a simple named pipe application on a single machine (no network!). A server creates a named pipe and a cllient reads/writes to the the server using a duplex pipe. The server is not multithreaded. The server has a main( ) and the client has its own main( ).

I am having huge conceptual difficulty understanding how the server with its main entry point can run at the same time as the client with its own main entry point. I keep thinking the two programs must be in different processes and therefore there must be a third program which creates the two processes, ie, the client and the server.

I have spent two fruitless days trying to hunt down examples of client/server and failed. The examples I have seen discuss the problem without clearly spelling out whether and how the client and server run concurrently. What I do know is that when I code the commonly available examples, I receive a message back saying that the pipe is could not be opened.

Any light that could be shown on this would be most helpful. If you could direct me to a good tutorial that clearly identifies the process architecture for this type of application that would be welcome too.

Sincerely,
Mark Allyn
May 8 '10 #1

✓ answered by allynm

Hello Everyone,

As often happens to me, after posting something and struggling some more, I get a solution. The answer is: Yes, you must indeed create a separate server process and a separate client process as well as a pipe connecting them. The program I wrote that does this is shown next:


Expand|Select|Wrap|Line Numbers
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <tchar.h>
  4.  
  5. int main( int argc, char * argv[ ]) 
  6. {
  7. static TCHAR ClientName[ ] = TEXT("pipeclient.exe") ;
  8. static TCHAR ServerName[ ] = TEXT("pipeserver.exe" ) ;
  9. TCHAR CommandLine[ ] = TEXT("Server Joe") ;
  10.  
  11. STARTUPINFO ClientStartupInfo, ServerStartupInfo ;
  12. PROCESS_INFORMATION ClientProcInfo, ServerProcInfo ;
  13. HANDLE hProcServ, hProcCli ;
  14. GetStartupInfo(&ClientStartupInfo) ;
  15. GetStartupInfo (&ServerStartupInfo ) ;
  16.  
  17. CreateProcess (ServerName, CommandLine, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS,
  18.     NULL, NULL, &ServerStartupInfo, &ServerProcInfo ) ;
  19. hProcServ = ServerProcInfo.hProcess ;
  20. printf ("Curr Server Process is : %d\n", hProcServ ) ;
  21. WaitForSingleObject(hProcServ, 1000) ;
  22. CreateProcess(ClientName, NULL, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, 
  23.     NULL, NULL, &ClientStartupInfo, &ClientProcInfo );
  24. hProcCli = ClientProcInfo.hProcess ;
  25. printf ("Curr Client Process is : %d\n", hProcCli ) ;
  26. WaitForSingleObject (hProcServ, INFINITE) ;
  27. WaitForSingleObject (hProcCli, INFINITE ) ;
  28. CloseHandle (hProcServ); CloseHandle(hProcCli) ;
  29. printf ("All Done!\n");
  30. return 0 ;
  31. }
Obviously, my client is in pipeclient.exe and the server is in pipeserver.exe.
The thing ain't pretty, but it works.

Any comments or suggestions on how to clean this thing up -- e.g, error correction code--would be appreciated.

Ciao,
'Mark

1 4296
allynm
20
Hello Everyone,

As often happens to me, after posting something and struggling some more, I get a solution. The answer is: Yes, you must indeed create a separate server process and a separate client process as well as a pipe connecting them. The program I wrote that does this is shown next:


Expand|Select|Wrap|Line Numbers
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <tchar.h>
  4.  
  5. int main( int argc, char * argv[ ]) 
  6. {
  7. static TCHAR ClientName[ ] = TEXT("pipeclient.exe") ;
  8. static TCHAR ServerName[ ] = TEXT("pipeserver.exe" ) ;
  9. TCHAR CommandLine[ ] = TEXT("Server Joe") ;
  10.  
  11. STARTUPINFO ClientStartupInfo, ServerStartupInfo ;
  12. PROCESS_INFORMATION ClientProcInfo, ServerProcInfo ;
  13. HANDLE hProcServ, hProcCli ;
  14. GetStartupInfo(&ClientStartupInfo) ;
  15. GetStartupInfo (&ServerStartupInfo ) ;
  16.  
  17. CreateProcess (ServerName, CommandLine, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS,
  18.     NULL, NULL, &ServerStartupInfo, &ServerProcInfo ) ;
  19. hProcServ = ServerProcInfo.hProcess ;
  20. printf ("Curr Server Process is : %d\n", hProcServ ) ;
  21. WaitForSingleObject(hProcServ, 1000) ;
  22. CreateProcess(ClientName, NULL, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, 
  23.     NULL, NULL, &ClientStartupInfo, &ClientProcInfo );
  24. hProcCli = ClientProcInfo.hProcess ;
  25. printf ("Curr Client Process is : %d\n", hProcCli ) ;
  26. WaitForSingleObject (hProcServ, INFINITE) ;
  27. WaitForSingleObject (hProcCli, INFINITE ) ;
  28. CloseHandle (hProcServ); CloseHandle(hProcCli) ;
  29. printf ("All Done!\n");
  30. return 0 ;
  31. }
Obviously, my client is in pipeclient.exe and the server is in pipeserver.exe.
The thing ain't pretty, but it works.

Any comments or suggestions on how to clean this thing up -- e.g, error correction code--would be appreciated.

Ciao,
'Mark
May 9 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: piyush | last post by:
Sorry for repeated posting but I couldnt get things right/completely in the first post. I am in the process of deciding the IPC mechanisms to use for communication between 1) An application...
5
by: glenn.owens | last post by:
In the process of doing some routine monitoring/clean-up we've discovered that several (many?) users are apparently set to access our SQL Server 2000 database instances via the Named Pipes...
2
by: Rudolf Bargholz | last post by:
Hi, DB2 7.1 FP11 Windows 2000 Earlier this evening, after dropping and recreating a trigger, DB2 locked up. I am not entirely sure that the cause of the problem was the replacing of the...
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...
0
by: piyush | last post by:
Sorry for repeated posts, I couldnt get things right and complete in the previous post. I am in the process of deciding the IPC mechanisms to use for communication between 1) An application...
1
by: Jarrod Morrison | last post by:
Hi All Im looking for a way use named pipes between a service app and an app run when a user logs on and be able to pass string based data, im hoping that the service can contact the app that is...
0
by: J.G. | last post by:
I am attempting to use SQL Server 2000 for my session state management with an ASP .NET 2.0 application. When I attempt to run the application, I get the following error: Named Pipes Provider,...
2
by: fahad.usman | last post by:
I am making an application in which if the second instance of the same application is launched, it checks its command-line arguments and passes them to the already running instance. I have been...
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...
2
by: simkar | last post by:
Error: provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server SqlException (0x80131904) General Info: Application is on server1(outside the firewall)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.