tags:

views:

320

answers:

2

I am working on a debugger project for a game's scripting engine. I'm hoping to write the debugger's GUI in C#. The actual debugging engine, however, is embedded in the game itself and is written in a mixture of C, C++, and assembly patches.

What's the best way to handle communication between the debugger GUI and the debugging engine? The two will be running in separate processes.

Thanks!

Andy

+2  A: 

If you can require Windows Vista or later, and .Net 3.5 or later, Named Pipes provide simple, high-performance IPC. Check out this article.

Dour High Arch
Named pipes work in XP, and in .NET 2 (via PInvoke) - so they're a good option always.
Reed Copsey
And, hell, on Unix, too, since nobody brings it up.
Jon Purdy
Can't you take this a step further and, in the C# implementation, implement this with WCF using named pipes?
Jaxidian
+1. for me WCF over named pipes.
kenny
Named pipes it is. Thanks fellas.
Andy
+2  A: 

I did this a couple of years ago. Script debugger was written in C#, and ran on PC; script runtime was written in C++, and ran on everything we supported at the time -- PC, PS3, Xbox360, Wii, DS, PSP and PS2.

Whatever you're targetting, I'd recommend putting in some kind of layer so that the debugger and runtime are insulated from the underlying protocol. Keep the API calls where you can keep an eye on them! This //leaves your options open, and (if done right) simplifies the code at both ends. Some kind of packet-based system, with packets of 1K or less, maps tolerably to just about anything. (Transmission of >1K can be accomplished at a higher level, using only the public API.)

If you're only targetting PC, I recommend TCP/IP. It's network-transparent, everybody is familiar with its IP addresses and ports, it's no harder to use API-wise than named pipes.

For a next gen title, if you want to strike a good balance between cross platform compatibility and ease of coding, TCP/IP is still the way to go. Works on PC, Xbox360, and PS3.

(Regarding named pipes, SN's Target Manager will give you named pipe support for PS3 and PS2, as I recall, and it goes via the dev LAN port rather than the game LAN port, but Xbox360 doesn't support it at all. So it might be worth supporting it -- and it's your only option in PSP, if I remember rightly! -- but it's not a universal panacea.

Personally, I stopped after implementing TCP/IP support, and I'm quite glad I did! As a summary, the Wii and DS are both horrid, but in different ways, and unlike anything else. The PSP only supports named pipes, for some unknown reason. The PS3 and PS2 support TCP/IP, but only via the game LAN port. (The dev LAN port works differently. Don't use it. Ask your producer for more network cables and save your sanity.) The Xbox360 supports TCP/IP, but only if you're using the debug libraries, and only via the game IP. (The debug IP works differently. Don't use it.)

In short -- whatever you do, you'll need that insulating layer.

brone
Fortunately I'm targeting PC with both applications. I think I'm going to go with named pipes, and implement the insulation layer like you suggested. Now--What's the best way to implement such an insulation layer? I don't want to write one version in C++ and another in C#. Is there an easy way to use C++ code in C# without having to load it from a dll?
Andy
You can't get away from the DLL, but you could write C++ code, and use as-is in the game. Then write a shim in Managed C++, and compile that (and the C++ code) as managed C++ project for use in the debugger solution. That should be easy enough, and work fairly transparently. (For my part I just wrote the code twice, once in C++ and once in C#, and it wasn't too bad. I don't like to share code between game and tools if possible, the code just ends up getting pulled in 2 competing directions at once.)
brone