Development
PHP SoapClient Could Not Connect to Host
Apr 17th
The Could Not Connect to Host error message when using PHP SoapClient can be a tricky sucker to trace the root of. There are varying responses across the internets to what may cause this problem such as firewalls and proxies.
But there is one other thing you can check. Look through the WSDL for the soap:address locations. You may find that a server name is given that the machine running your code does not have access to.
Take a look at the example below;
<service name="SomeService"> <port binding="tns:WebServiceBinding" name="WebServicePort"> <soap:address location="http://appserver3:8080/webservices/WebServiceEndPoint"/> </port> </service>
I experienced the issue when deploying my code from my dev machine to a live server. I couldn’t understand why my dev machine was fine calling the web services and the live server was not.
That’s because I had forgotten that I had provided access to my dev machine in the early days of coding to the appserver3 server name by virtue of a hosts file entry. Looking in my hosts file revealed
123.123.123.123 appserver3
And this is what was missing on the live server.
So if you get this error and you just can’t figure it out, take a wander through the WSDL for location URLs that may not be accessible to the server running your code. If you have a server name rather than an IP as in the example above, then add a hosts file mapping to the IP and you’re away.
Using XNA DrawableGameComponent
Apr 8th
This post is for those thinking about using the DrawableGameComponent class in the XNA framework.
I am going to demonstrate how you might use the class by using the example of dice.

Project Files
Download Dice.zip for the Visual Studio Express 2005 XNA 2.0 project files. Extract the zip, then run Dice.csproj to open the project in VSE 2005. You can then just compile the project by pressing the play icon.
DrawableGameComponent
Dice are ideal for illustrating the DrawableGameComponent class because dice, even in the real-world, are reusable across many table games, and that’s really where DrawableGameComponent comes in handy.
The DrawableGameComponent provides the developer a nice structured way to create modular, self-contained and reusable game components. A component should by definition be able to be dropped into a game and with minimal wiring up, just work.
Understanding the Source
The way in which to use DrawableGameComponent is to extend it. By doing this, when we add our component to the game, the XNA framework will know how to call it properly.
The Dice class therefore is made to extend DrawableGameComponent. The constructor for DrawableGameComponent requires the Game instance to be passed, so we need to ensure our component class constructor receives the game instance in addition to any specific variables so that it may pass the game instance on to the superclass for instantiation.
In essence when creating a component, you will want to override 3 of the methods of the DrawableGameComponent superclass; LoadContent, Update and Draw. For beginners, LoadContent is a method in which we instantiate resources like graphics and sounds, Update is used to update game logic (and this is done per game loop cycle – which is fast), and Draw in which we paint stuff to the screen.
You will see in the Dice class that I have overridden these 3 methods using the override keyword in the method declarations. Each of these methods as their last statement call the superclass’s version of the method to ensure the component is fully called.
A die has 6 faces, so I added 6 graphics files to represent each face of a die. These are added to the Content folder in the project. As such, within LoadContent, I am able to load them as Texture2D files.
A separate Die class represents a single die since the actual Dice class supports as many die instances as you want. In practice this will be 1 or 2, but hey, it’s all about extensibility!
The Die class contains a method for rolling the single die. It uses a static instance of Random to roll a random face between 1 and 6.
The Dice class also contains some logic methods. Roll iterates all the die instances and calls their Roll methods. And Total returns the sum of all die instance faces at the time of call.
Using the Dice Component
To use the Dice component, we need to add it to our main game instance. In Game1 we just have to add an instance of Dice to the Game.Components collection. Simple as that.
By doing this, each game update tick, the Dice component’s Update and Draw methods are called.
The Dice.Update method monitors the keyboard for presses of the Space Bar. This triggers a roll of the active die instances.
Dice.Draw draws the relevant Texture2D graphics for the active die instances.
In the project, I just draw out each die next to each other.
Keep pressing Space Bar and you will see the dice change as you roll them.#
Final Words
I hope this article was of use to some of you, particularly those starting out with XNA. The DrawableGameComponent method of encapsulating game logic is a really good pattern to follow.
Some of you may be wondering though – since the Dice class is constantly monitoring the Space Bar, when you add that to a real game, where you would want to block dice rolls until certain other events take place – how do you do that?
Well, you’d need additional wiring in that case. One idea might be to maintain a flag CanDiceRoll for example in the main game. The Dice.Update method would need to use a conditional block based on that flag to determine if it should roll. Suggestions from readers are welcome.
Recent Comments