Archive for March, 2012

Testing Code with the Mono Csharp REPL

March 21, 2012 2 comments

I’m porting a full enterprise application to Mono so it can be deployed on Linux as requested by customers. I’m using the term “porting” loosely, because really, I just need to verify the existing code will run under Mono and make some minor adjustments so everything runs cross-platform. The Mono csharp read-evaluate-print-loop (REPL) has been an invaluable tool in this process.

Take Active Directory authentication for example. This is one of the areas that the Mono framework is not compatible with the .NET framework. You can see this right away in the csharp REPL, and then work out a quick alternative with the lower level DirectoryServices libraries. Just type ‘csharp’ at the terminal on a Linux system with Mono installed:

csharp> LoadAssembly("System.DirectoryServices.AccountManagement");
error CS0006: Metadata file `System.DirectoryServices.AccountManagement' could not be found

No worries – the AccountManagement API’s aren’t there on Linux – it’s good to be able to find this out right away (you can also check the Mono GAC, but this is REPL school). Now we just need to verify that a lower level call will work:

csharp> LoadAssembly("System.DirectoryServices");
csharp> DirectoryEntry adsEntry = new DirectoryEntry("LDAP://,dc=local", "mydomain\\testUser", "testPa55w0rd");
csharp> var searcher = new DirectorySearcher(adsEntry);
csharp> var res = searcher.FindOne();
csharp> res.Properties;

It’s great to be able to do some quick API checks to understand and isolate compatibility issues right away. Go Mono REPL!

Categories: C#

Getting started with Twisted on Windows

March 10, 2012 Leave a comment

Twisted is an excellent networking framework for python applications, and like most of python, your code is easily portable from one platform to another. As an event-driven framework, you can handle very high loads without creating a large number of threads, so it scales quite nicely. Twisted comes preinstalled on recent versions of Mac OS X, and on Linux distros you can get it with your system’s package manager. Windows is a bit more work, so I’ll go through the steps.

The prerequisites:

Python –
Setuptools – (needed to install the Zope Interface egg)
Zope Interface – (used by twisted for its service interfaces)
Twisted –

1. Install Python from There are Windows installers aplenty.
2. Install setuptools. There is an installer for 32-bit windows. For 64-bit, just download the locally, and then run “c:\Python27\python.exe c:\Users\me\Downloads\”
3. Zope is a little tricky. When you installed setuptools, it added the easy_install.exe under your python\scripts directory. To install the python .egg file containing zope, you need to get the URL for the zope egg you want to download and pass that as a parameter to easy_install.exe, like this:


If all goes well, you should be ready to install and run twisted.

4. Install twisted from

At this point, you should be able to fire up python and run the sample from the Twisted home page:

from twisted.internet import protocol, reactor

class Echo(protocol.Protocol):
    def dataReceived(self, data):

class EchoFactory(protocol.Factory):
    def buildProtocol(self, addr):
        return Echo()

reactor.listenTCP(1234, EchoFactory())

I hope this helps you getting started with the excellent twisted network framework for your python apps.

Categories: python, twisted Tags: , ,