Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

COM port simulation: Named Pipes

Posted on 2002-04-22
7
Medium Priority
?
305 Views
Last Modified: 2013-11-20
I do not have 2 COM ports on the back of my PC, so I am trying to use an internal software pretend comport.

I am trying to use Named Pipes, as I require bidirectional FIFO comms. However, the examples I have seen all depend on knowing whether you are programming the client or server end of the pipe.. i.e. server: CreateNamedPipe().... Client: ConnectNamedPipe()...

I am trying to encapsulate this in a class so I can use the same code in both client and server ends... which ever end starts first will create the pipe, and which ever is last out will close the pipe. (hopefully, windows is clever enough to know that when I CloseHandle() the last one out will destroy the resources??? )

Any Ideas please???

Thanks.
Nigel.
0
Comment
Question by:nigel5
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 6961098
THis article contains cod that creates a CNamedPipe class, derived from CFile.  It should answer all of your questions.

Garden Hoses at Work
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpic/html/msdn_npipes.asp

A quick read indicates that the author does *not* expect to make the ends of the pipe interchangeable.  One end is the server and one is the client.  But remember that communication is bidirectional, so it doesn't really matter which end is which once the connection is established.

-- Dan
0
 
LVL 3

Expert Comment

by:danny_pav
ID: 6962871
You can't make the ends interchangeable.

The closest you can do is to make your client continuously try to connect to a server.
0
 

Author Comment

by:nigel5
ID: 6963872
Ah, and if it can't connect, then it can open the server end...

Cool...

I'll give it a go.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:nigel5
ID: 7246175
Sorry for not getting back for a bit, but been doing lots of other things...

If you test to see if the pipe exists first you can either attach to it if it exists, or create it if it doesn't. That way you can make the same class handle the work, and you don't have to worry about the concept of server/client.

When you close the hanldes, Windows handles the cleanup, so the server can disconnect first, and the pipe can still be connected to by another process.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7247313
nigel5,
If you have answered this question yourself, please post to Community Support and ask for a refund.  Better to finalize this now and save work for the database cleanup crew.
-- Dan
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 11462037
PAQed, with points refunded (200)

DarthMod
Community Support Moderator
Experts-Exchange
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question