Quantcast
Channel: Photon Server — Photon Engine
Viewing all articles
Browse latest Browse all 1557

How to debug server code

$
0
0
Couple of methods I came up with for debugging server code. Hope it will help someone to save up some time. :-) Btw I'm using Visual Studio 2008.

First, be sure to setup your Visual Studio project to update server's files automatically. There are two ways to achieve this: 1) go to your server project properties, and in Build tab select Output path to point to the path were Photon is loading your dlls (for example: "e:\Projects\Photon\Server\deploy\Mmo\Photon.MmoDemo.Server\bin\"). 2) Another way to do this is to go to Build Events and add a post build event to copy the files there. Something like: "copy "$(TargetDir)" "$(SolutionDir)\..\..\deploy\Mmo\Photon.MmoDemo.Server\bin\"", also don't forget to choose Run the post-build event: When the build updates the project output. Setup Photon to automatically load changed dlls, and after you hit F5 or Ctrl+Shift+B in Visual Studio, the files will end up were they should be, and Photon will restart the server with your new code.

Now for the debugging part, there are 3 methods. But before debugging make sure Photon is using 2.0 version of .Net runtime! To do this edit your PhotonSocketServer.config file and for instance config add this:
<Runtime
	Assembly="PhotonHostRuntime, Version=2.0.0.0, Culture=neutral"
	Type="PhotonHostRuntime.PhotonDomainManager"
	CLRVersion="v2.0">
</Runtime>

1. Attaching debugger.

Go to Debug -> Attach to Process, select PhotonSocketServer.exe. Also for Attach to: select only Managed code. If you select Native code, then detaching debugger will kill server process. After that hit Attach, and there you go.

2. Launching debugger from your code.

In your Application class (the one that inherits Photon.SocketServer.Application) override Setup() method and add this line: System.Diagnostics.Debugger.Launch(); . When your server code will be launched you get a nice message box that will ask you if you want to attach the debugger. You can debug startup code this way!

3. Attaching debugger automatically.

This one is my favorite, as it attaches the debugger by simply clicking F5 in Visual Studio. For this create a dummy empty C++ project in your solution. Add main.cpp and a stub for main(). Select it as startup project. Setup project dependencies that building this one will build your server too. Go to project properties and in Debugging tab change Command to where PhotonSocketServer.exe is located, for example: "e:\Projects\Photon\Server\deploy\bin_Win32\PhotonSocketServer.exe". For Attach choose Yes. Set Debugger Type to Managed Only (mixing with native kills the server after detaching debugger). And voila! Hit F5 and it will compile, update your server, and attach a debugger in just a couple seconds. :-) And you can debug startup code this way too!

Viewing all articles
Browse latest Browse all 1557

Trending Articles