Using Named Pipes with C#??
-
Has anyone had any experience with, or advice on how add named pipe functionality to an otherwise run of the mill C# Windows Form application? I've got a project to write a utility to interface a special piece of hardware (a custom video camera which has a C# .NET namespace provided by the maker) to another master control program. The problem is the master program is an old legacy program that only gives remote commands (start, stop, report status, etc.) using named pipes. I've searched through my C# and .NET references and don't see any namespaces or managed classes to provide named pipe remoting access. My best guess is somehow import them through the Win32 api functions, but my search efforts so far haven't given me any examples close enough to what I need to really get a good feel for how to go about this. This was pretty straight forward back in the old VC 6 days using MFC functions, but I don't think they made it to C# yet. Any advice, recommendations, links or examples would be most welcome (except telling me not to use named pipes or C# .NET, those are the two things I have no control over). Oh, and if it makes any difference (probably makes it worse with my luck) I'm using VS 2003 and .NET 1.1. Having enough fun going from my comfy old VC++ to C# as it is, without having to leap to the changes they made in 2.0 and 2005.
-
Has anyone had any experience with, or advice on how add named pipe functionality to an otherwise run of the mill C# Windows Form application? I've got a project to write a utility to interface a special piece of hardware (a custom video camera which has a C# .NET namespace provided by the maker) to another master control program. The problem is the master program is an old legacy program that only gives remote commands (start, stop, report status, etc.) using named pipes. I've searched through my C# and .NET references and don't see any namespaces or managed classes to provide named pipe remoting access. My best guess is somehow import them through the Win32 api functions, but my search efforts so far haven't given me any examples close enough to what I need to really get a good feel for how to go about this. This was pretty straight forward back in the old VC 6 days using MFC functions, but I don't think they made it to C# yet. Any advice, recommendations, links or examples would be most welcome (except telling me not to use named pipes or C# .NET, those are the two things I have no control over). Oh, and if it makes any difference (probably makes it worse with my luck) I'm using VS 2003 and .NET 1.1. Having enough fun going from my comfy old VC++ to C# as it is, without having to leap to the changes they made in 2.0 and 2005.
TCP/IP sent to localhost, uses Named Pipes under the hood I'm told. That's a reasonable swap. Otherwise you have two basic options. If you want to use Named Pipes in C# for a general mechansism then its off to P/Invoke land. But unless you have to interface to an older C/C++ program that used Named Pipes, you might consider leveraging some of C#'s data structures and particularly the TCP classes. Secondly, if you are using SQL Server, Microsoft has carried over Named Pipes for that. That's easy to take advantage of. I guess there is one 3rd option which may or may not make sense. Since you have a heap of code in C++, you could hobble together a C# callable DLL and provide the underlying Named Pipe support. In sum, Named Pipes appear to have been relegated to performance driven 3GL/2GL apps. With some effort you can force an implementation in C# but you have to ask: "why am I doing this?" Good luck Mike Luster CTI/IVR/Telephony SME
-
TCP/IP sent to localhost, uses Named Pipes under the hood I'm told. That's a reasonable swap. Otherwise you have two basic options. If you want to use Named Pipes in C# for a general mechansism then its off to P/Invoke land. But unless you have to interface to an older C/C++ program that used Named Pipes, you might consider leveraging some of C#'s data structures and particularly the TCP classes. Secondly, if you are using SQL Server, Microsoft has carried over Named Pipes for that. That's easy to take advantage of. I guess there is one 3rd option which may or may not make sense. Since you have a heap of code in C++, you could hobble together a C# callable DLL and provide the underlying Named Pipe support. In sum, Named Pipes appear to have been relegated to performance driven 3GL/2GL apps. With some effort you can force an implementation in C# but you have to ask: "why am I doing this?" Good luck Mike Luster CTI/IVR/Telephony SME
mcljava wrote:
TCP/IP sent to localhost, uses Named Pipes under the hood I'm told. That's a reasonable swap. Otherwise you have two basic options. If you want to use Named Pipes in C# for a general mechansism then its off to P/Invoke land. But unless you have to interface to an older C/C++ program that used Named Pipes, you might consider leveraging some of C#'s data structures and particularly the TCP classes. Secondly, if you are using SQL Server, Microsoft has carried over Named Pipes for that. That's easy to take advantage of.
Yeah, but the trick is figuring out how to use these classes and if they will actually work or not. I have no control over the other program I'm interfacing with, I just have a pair of named pipes for talking and listening and a list of commands I can expect to receive and replies I need to make. Whether the TCP classes happen to use pipes or not doesn't mean anything to me. I need to open a specific pipe, wait for a command from another program (which is not of my design or control) and give it a response telling it my status. That program uses named pipes and it's the only hook available for communication.
mcljava wrote:
Secondly, if you are using SQL Server, Microsoft has carried over Named Pipes for that. That's easy to take advantage of.
Nope, not using SQL server.
mcljava wrote:
With some effort you can force an implementation in C# but you have to ask: "why am I doing this?"
Well, I'm doing it because that's my job...LOL. Unfortunately every time a new technology comes along half the world jumps on the bandwagon thinking it's the next best thing since cake and the other half is relegated to trying to make it work with all the stuff that's been done before. In this example, I have a c# .NET namespace which is the only way to access one piece of hardware, and a named pipe scheme which is the only way to talk to the master program. I'm caught in the middle and have no say in how either one is done. I really appreciate you giving this one a shot, truly, but I'm afraid I'm left just as confused as to how to accomplish this as I was before. Anyone know of any books, texts, articles that covers this, or at least dance around the topic enough that I might glean some ideas? Could there be some way to tap into named pipes using the Win32 API? The Win32 API examples I've seen al
-
mcljava wrote:
TCP/IP sent to localhost, uses Named Pipes under the hood I'm told. That's a reasonable swap. Otherwise you have two basic options. If you want to use Named Pipes in C# for a general mechansism then its off to P/Invoke land. But unless you have to interface to an older C/C++ program that used Named Pipes, you might consider leveraging some of C#'s data structures and particularly the TCP classes. Secondly, if you are using SQL Server, Microsoft has carried over Named Pipes for that. That's easy to take advantage of.
Yeah, but the trick is figuring out how to use these classes and if they will actually work or not. I have no control over the other program I'm interfacing with, I just have a pair of named pipes for talking and listening and a list of commands I can expect to receive and replies I need to make. Whether the TCP classes happen to use pipes or not doesn't mean anything to me. I need to open a specific pipe, wait for a command from another program (which is not of my design or control) and give it a response telling it my status. That program uses named pipes and it's the only hook available for communication.
mcljava wrote:
Secondly, if you are using SQL Server, Microsoft has carried over Named Pipes for that. That's easy to take advantage of.
Nope, not using SQL server.
mcljava wrote:
With some effort you can force an implementation in C# but you have to ask: "why am I doing this?"
Well, I'm doing it because that's my job...LOL. Unfortunately every time a new technology comes along half the world jumps on the bandwagon thinking it's the next best thing since cake and the other half is relegated to trying to make it work with all the stuff that's been done before. In this example, I have a c# .NET namespace which is the only way to access one piece of hardware, and a named pipe scheme which is the only way to talk to the master program. I'm caught in the middle and have no say in how either one is done. I really appreciate you giving this one a shot, truly, but I'm afraid I'm left just as confused as to how to accomplish this as I was before. Anyone know of any books, texts, articles that covers this, or at least dance around the topic enough that I might glean some ideas? Could there be some way to tap into named pipes using the Win32 API? The Win32 API examples I've seen al
-
Phil, Fire up google, and ... "C# named pipes" - it will lead you to at least a dozen or so C# Named Pipe Examples. Good Luck Mike Luster CTI/IVR/Telephony SME
Ah whew...I looked again, thanks. Obviously this was the first thing I did when I first took this on. Perhaps my google skills need polish, I don't know. Everything I found seemed to be pointed at the new IPC remoting stuff that's in .NET 2.0. I Found an example on codeguru and it does compile and run with my 1.1, so I'm golden. It's buried inside InterProcessCommunication stuff. I guess since my C++ and MFC experience all had it built into CreateFile and it was right up front and as basic as opening a file I assumed the CSharp would be there too (obviously it isn't) Thanks for the gentle shove in the right direction :) Just what I needed.