Friday, April 23, 2010

HOWTO: Silverlight-to-Mono Client-Server, Part I

The premise of this HOWTO is that you'd like to build some shiny new web-based application, something that needs data comm to a back-end server, and for whatever reason, your preference is to do it using C# and the .NET framework.

Using Silverlight for the client is the obvious choice, perhaps the only one for our given scenario. (ASP.NET - what's that?!) On the back end, you can write the server as a straight-up .NET console application. If you were deploying to a Windows server you might even make it a bona fide service; that would be a smart idea. But let's add a different wrinkle and say that your server is actually going to run on a Linux box. What then? Well, the answer is, of course, Mono, which will run our .NET application CLR in Linux-land.

Nothing novel here: a quick search reveals other web articles on the topic. But as I've started to work through the actual implementation, I've come across the interesting bits. You know, where things don't work right. That's what I think is worth sharing.

First, installing Mono on the server. Mine is a Debian Linux distro. I followed the steps in this article: made /home/username/scripts/install-mono, copied the referenced bash file over, set the domain to mydomain.com, and ran it. After a good 20 minutes of churn and work... success!

On my development PC, I'm using (the free) Microsoft Visual C# 2008 Express. I made a simple "Hello, World" console app to begin with, then moved the application executable over to my server (WinSCP is my typical tool of choice), ssh'd in (Cygwin or PuTTy) and ran "mono HelloWorld.exe". Lovely!

Next comes the first baby steps of networking. I want to use System.Net.Sockets based TCP/IP rather than a WebClient protocol. Mostly, because I believe that this will let me effectively push data up to the client from the server asynchronously. I don't want to get into extraneous polling, or have a strict client-driven request-response system. Someday, we'll see why that was a good idea; or perhaps not.

When a Silverlight app uses a TCP socket, certain network security access restrictions apply. For TCP, they apply even when your server app is on the same domain as the client app, and it applies for cross-domain netowrking of any kind. Now here's where some sources get a bit glossy. When you first try to connect with a Silverlight TCP socket (and it's restricted to destination ports in the range of 4502-4534), it goes (behind the scenes) to that server to retrieve a clientaccesspolicy.xml file, which has the rules to determine whether or not the client is allowed to talk to this server address.

"Behind the scenes" sounds magical, but it's not. At least not on the server side. In reality, you need to have an authentication service of some sort listening/accepting on port 943, which is where Silverlight is hard-coded to connect to. SL, once connected, sends a message: "", and the authentication server responds with the clientaccesspolicy.xml data (which is fairly mundane and not even today's subject). Well, no one is running this authentication service for you (probably; maybe you are running something like FreeRadius and know how to configure it to handle this; but, like me, you probably aren't).

The simplest thing to do, then, is to make our server app also be the authentication server, which means that before a Silverlight client can TCP connect to us (again, in the port range of 4502-4534), we first have to handle a listen/accept on port 934 and serve up the client access policy to whoever might ask for it.

When you do this (code not shown, exercise for the reader) and run, the server application crashes when it tries to create the listener on port 943. Why? Oh, well, in Linux any port number under 1024 is considered "privileged" or "well-known" and can only be opened by an app running as root. That's crazy! So, what can we do?

The first option, the bad one, is to run as root. This is such a bad idea that we're not even going to seriously consider it. But many native Linux apps are built to do something just like this: they are started under root, and then drop their root privilege as soon as they've created their critical sockets. I think this is what Apache does. I'm not sure how you would go about doing that in a .NET/Mono app, anyway. So let's move along.

Better options exists. This article has at least two worthy of consideration. The first one is to use firewalls via iptables to setup the kernal network stack to redirect a port, say 943, to another, say 4501. Then we would be able to run our server without being root, accept/listen on port 4501, which is where the Silverlight client authentication requests coming in on port 943 would be redirected in a fairly magical fashion. So that's one good idea.

The next one is to install and use the authbind package on the server, which would allow a specific port such as 943 to be used by some specific designated non-root application, such as our server app. This seems to have some merit, too, but overall it's a bit more fiddly, and the iptables approach seems to make better use of inherent Linux capabilities, with far less extra fuss and muss.

Let's stop right there, what a cliffhanger! In Part II, we'll tackle getting the Silverlight client authentication to work in practice on our .NET/Mono server app.

Friday, April 16, 2010

Cruising To The Outlandish

My decade of PT Cruiser ownership is over. After weeks of research and searching, we traded up to a small SUV, so much the better to meet the needs of our parental hauling stuff around allotment.

So meet the new boss: it's a 2007 Mitsubishi Outlander LT with 34,000 miles - that's a full 100,000 miles less than what the Cruiser ended at. The 'lander has a 3.0L V6, 6-speed automatic tranny, selectable 2WD/AWD/4WD drive, great interior space and sensible layout and features, fuel efficiency on par with the cruiser, and the balance of the 5-year, 60,000 mile full vehicle warranty on top of all that. It was right up there with a newer RAV4 on my with list, and those are both harder to find and pricier. So I think we're in great shape with the Mitsu. If previous experience holds true, they're very reliable.





Sunday, April 11, 2010

Titan Tournament: The Red Fist Of Death Tells All!

Yesterday, I took home the trophy in the inaugural SWA-sponsored 2010 Northeast Titan Tournament. This followed a pair of preliminary rounds during the previous month. Titan’s the sort of game that makes for great stories – if you like Titan. Otherwise, not so much. So you’re been warned: keep reading at your own peril.

Based on the structure of the tournament, I guessed that was going to need to win two games in the open pool prelims in order to get a seat at the finals. Since my gaming free time is not what it used to be, this was no sure thing. On the first weekend of games, I was the first one out of a three-player board; I was re-learning a lot of Titan nuances in a hurry, having not played seriously for almost ten years. (Oh, and running on four hours’ sleep after a band gig in Pine Plains the night before.) Not an auspicious start! Fortunately, I stuck around for an afternoon session where I won a four-player bout by being the leader when time was called at seven hours. No one got eliminated, but I had built up a pretty powerful Titan and I think everyone agreed that I was the leader at the time. So that was one win – halfway there.

On the second weekend of prelims I only had time for one game, so it was going to have to count. Again, a four-player match, and again facing off against the SWA’s John F., a very good player, easily my better at mastering and moving on the main board. John was already the points leader at this time, but I had outlasted him in my first win earlier. This time around, though, it didn’t go on time: titans went down hard. I managed to devise a train wreck of sorts on the main board, where I was in the best position to clean up the pieces. It worked to plan, and I came out of it with a tough Titan in a non-mustering stack, and not much else. The real upside was that I eliminated two other players, and John maxed out at 12 legions and was denied the use of extra legion markers from eliminated players. I got through that dangerous run of turns when your Titan’s not tough enough to win on his own, and doesn’t have enough of a legion to help or muster with. The end came surprisingly fast, then. A few decent rolls brought me a Warlock, and Angel, and I rolled a ‘6’ on my first chance with Titan Teleport, picked out John’s Titan legion from clear across the board, and shredded it with a combination of Angel-Warlock firepower. His stack was full of strong Jungle creatures, but all those x-2’s are like cheese against angels and warlocks and Titans. So I got my seat at the finals, and had also definitely re-located my Titan mojo.

Which brings us to yesterday’s final. The top six contenders from the prelims were invited, but two were unable to attend, so we again had a four-player setup, using balanced towers to be fair. Honestly, a six-player game is so crowded and full of random mayhem that a four-player final probably made for a better game anyway. It was me, John, Mike, and Nick, who was also the tourney organizer and deserves a big shout-out of praise for the effort and smooth execution thereof. Cheers!

Certain trends emerge when you play a bunch of the same game in a row. As I’ve said, John is excellent on the main board – he gets a lot of good musters and keeps great board position while doing it. Me? Not as good. Even in a ‘serious’ game like this one I don’t keep as close track of what everyone else is mustering as I should, and I always have a very hard time favoring my own long-term mustering tracks versus something I could use right now. I do tend to be pretty mindful of board position at least. But, no, without a doubt my real talent lies on the battle board. I have a very good feel for how to run a battle, and I feel that I often have an advantage over my enemies even when the material is balanced. I humbly credit this prowess from all the whippings I received (and sometimes gave) back with my Buffalo Titan friends from back in the day: Random, Tom, and especially Kevin, who I think can bend the dice to his will. Oh, and I move fast, which I think unnerves some opponents. I’m not into pondering that board for ten minutes each combat phase. Like Antony says, when the battle is in doubt, charge. Using a football analogy, I run the Titan equivalent of the West Coast Offense. Run and gun, run and gun.

OK, so this final got off to a very ‘classic’ start: lots of mustering and splits, a very few cautious probes of battle, but overall conservative, even tentative, play. I myself was doing better on the main board than usual – at its high-water mark my Titan stack featured: itself, a Warlock, two Unicorns, two Manticores, and, well, an Ogre. I also had a jungle legion that got itself a Serpent before all was said and done. Good for me, but others were doing about as well.

The first real game-changing event happened as result of some of my earlier aggressions. I had taken on a combat that was rather a toss-up, and summoned my angel for the win, but it left that stack with but a Cyclops and the angel. For a bunch of turns I kept it out of harm’s way – it was my angel buffer, and I desperately tried and failed to pick a fight elsewhere: I wanted to summon that angel back to a ‘real’ stack and kiss the Cyclops good-bye. But I simply couldn’t get the opportunity. Then, I moved the Cyclops-Angel stack down close to a tower, on the chance that I might just get in for safety and a new basic recruit. On the way, I stopped next to Mike’s Titan legion. Now, John was coming around the outside with the scariest conga-line of legions any of us had seen in awhile. And so Mike rolled his titan legion into my stack mostly for the sake of the safer board position my space would offer.

I looked at his stack: I think it was an Angel and three Centaurs in addition to the Titan. A bit weak given that we were mid-game: his fear of John’s legions was justified. My big mistake of the day: I offered him full points with no battle if he’d lose two of the Centaurs. Mike’s bigger mistake: declining (he’d have gotten one back right away in post-battle muster). We were in the Woods and I think he wanted to at least try to off me with no losses to recruit a Warbear. So, to the battle map we went…

The Cyclops lumbered in and the Angel kept pace. Mike’s creatures didn’t close to combat. So the next phase, I did. I got the Angel and Cyclops double teaming a Centaur, the Cyclops’ flank exposed to another. The trees in the woods were a big help. I snuffed his Centaur, which whiffed on the retaliation. On Mike’s next move, he sent another Centaur into the same breach, instead of his Warlock. And he tried to finish off the Cyclops, I think. In any case, the Angel waxed his Centaur as well on the retal and was now unlocked from melee. On my next move I flew over to his Titan (and Warlock). I hit exactly for odds, three hits on the Titan, and the eleven dice of retal from Titan and Angel only got five hits. So I lived to the next round and hit for odds again, three more, and Mike’s Titan fell. The battle itself was mutual destruction, but Mike was eliminated, I got a ton of half-points, and a lot of board space to work with. Let’s just say that one more time: a Cyclops and an Angel taking out a Titan stack. Woof!

At this point, Nick was hemmed in on the board and falling behind in the muster race, but John was getting nervous: he’d seen me go on a Titan rampage in our last game. So he made the next bold move and sent his ‘Air Force’ legion (4 Rangers, 1 Wyvern) against Nick’s Titan legion that was holed up in a Tower. Nick’s stack was decent enough: a Warlock, some Gorgons, and he should have come out weakened, but alive. Instead, John’s flying range-strikers negated most of the Tower’s inherent defense, and then when they made their suicidal charge on Nick’s Titan, he rolled very, very well. I think there was a point in this battle where Nick’s forces needed to abandon the ramparts, and close on the Rangers in pairings of his own choosing. He put too much faith in John only rolling average, and that’s a game with a high cost to losing when your Titan’s on the line.

So now Nick was gone too, and John, with all the points picked he up, was winning. I smashed my Titan legion straight into one of his tougher stacks, expecting few losses, an Angel summon, and a Unicorn muster. But again, John’s dice were hot, and while I won the battle, I came out with only the Titan, a Warlock, an Angel, and one Manticore. A few turns later I Titan Teleported onto a small, nasty stack of his in the hills, hoping to grab another Manticore, but instead lost the only one I had in the process. I was down to all lords, no mustering potential, and a weak stack at that. But for the next bunch of turns, John couldn’t roll a six to get his own Titan Teleport to stomp me. And just low numbers all around for him, he couldn’t even close with conventional moves. It was just enough time for me to pick my way through a few other battle wins and get an Angel and Archangel into the mix. My hot jungle stack with the Behemoths and Serpent gave me just enough swagger (I was down to three legions total) to not be forced into any bad moves.

Somewhere in there, his Titan stack took out my last speed bump legion. This was good for me, because I had lost track of his Titan, being such a lazy main board player. And for the end game, it was weak! Four Lions, a Ranger, a Warlock, and the Titan. My teleport potential meant he couldn’t risk a split anymore, either. I got close to him and he declined to come after me (he had no angel to summon), and I knew I had him. I got a good roll the very next turn and took him on, lions and all, in the desert.

On paper (cardboard?) it looked like it might go either way, but once the swords came out, it was a rout. My Titan was a 13-4 at this point, against his 11-4, but I also brought two Angels (6-4), a Warlock (5-4), and an Archangel (9-4) to the party. All those flyers, again, essentially negated the terrain advantage for the lions and defenders. And the sand wasn’t helping his non-natives adjust easily, either. I got my Archangel two hexes from his Titan, pasting the Lion that stood between, and my Warlock bringing up the rear to start range-striking his Titan. He was flushed out, to no better position, and this time I had the hot dice on the retals and cleared some spots next to his Titan. Next turn all my tough guys rushed in and finished him, and even if his Titan got all 6’s on the retal, it wouldn’t be enough to take mine out. Victory!

So that’s how I came to be the 2010 Northeast Titan Champion. Everyone seemed to have a good time and the quality of play was extremely strong. I will post some pictures if I can get Nick to send them along. Nick’s going to tweak the format a bit from lessons learned, but I think it’ll be back and even better next year, and I’ll be there to defend my title. Just as long as I can play the Red Legion!

Friday, March 26, 2010

Idiot Splendour Gets All Welshy in Chatham This Saturday

The 'Splendour sets down in the uniquely named Peint O Gwrw Welsh pub in Chatham this Saturday night. It's practically a matinee show: 8-11 PM, and at less than ear-blistering levels, too. And we hope to unveil our rendition of Peter Gabriel's "Sledgehammer". What's not to like? Drop in and say hi!

Dapper Charlie

This past weekend we got Charlie his nice clothes for Easter, and yesterday Kathleen got some pictures taken. (We also squeezed in the "I am 1" theme even though he's already about to hit fifteen months.) He is just adorable!

Thursday, March 18, 2010

Happy 3rd Birthday, Loki!

Loki was "about 5 months" when we adopted him August of 2007, so we proclaimed that March 17th was his official birthday. So yesterday was his 3rd birthday!

Here he was in October '07, still a young nipper:



All grown up now, fifty pounds even, lots of playful energy and great friends with 'lil Charlie, here he is now:



I took him to the doggy park yesterday as a special treat. There were about seven other dogs there at the time and he ran and ran and played and played.

Friday, March 12, 2010

Ongoing goings on...

Posting has become sporadic... at best... so, my apologies!

The new Idiot Splendour lineup heads out for our 2nd showing tonight, down at Lia's Mountain View in Pine Plains - down the Taconic we go! After looking at a map, I realize that Pine Plains is just about halfway between me and my brother John's place down in Mount Vernon. I've got my guitar wireless all sorted and levelled out and am looking forward to using it.

Over the last couple weeks I've been working to add sax into the band repertoire, starting with our bluesier covers and a few select originals. If I can strong-arm Mark into singing and playing rhythm guitar parts of my own devices, this opens the door to doing a whole bunch of nice originals that I wrote with sax in mind as the lead instrument. "Alexander" and "Give Yourself Away" are already in the works. Unlike my previous bands, where a "clean" sax sound was the rule, running with the 'Splendour crowd means I need to get an effects box for the sax signal chain and get to experimenting. Craigslist, here we come. Maybe the Zoom A2 acoustic box will do.

In other pursuits of the geeky variety, I've been reading through Zelazny's Amber novels (just finishing the Corwin Chronicles now, moving on to the Merlin cycle...), and watching the original Firefly TV series on DVD, and also HBO's Rome, season 2. I want to find a nice XIII legion t-shirt to wear at band gigs! But, so far I've been frustrated in attempts to find someone with Galactica season 2.0 on DVD that I can borrow it from; it's no-go at our branch of the library. Also, tomorrow I hope to play a couple preliminary rounds of Titan at the SWA's Northeast Titan Championship. It's going to be tough, I need to get through at least two games and place well to get on track to make the finals. And I'll be wickedly sleep-deprived to boot. The only hope is that this will allow my natural wicked streak as a Titan player rise to the forefront...

Meanwhile, the nice weather has been most welcome. Charlie's loving being outside in his wagon and going on walks with the family. He's also enrolled in a "swim" class at the Y with mommy. You can see how he's slimming out:



He also got a really nice kitchen set as a belated birthday present, and he's loving it:

Friday, February 12, 2010

New Splendour Begins

I thought it worth mentioning that Idiot Splendour, the band I've been practicing with since last September, has finally made it to the starting line: we play this Saturday at 9 at O'Toole's in Colonie. A strange and crazy mix of original prog-post-punk-rock alongside tasteful covers from classic to modern, it's sure to bewilder, and perhaps even entertain. And if that doesn't work, there's sixteen varieties of beer on tap.