26 September 2008

WowzaMediaServer using Amazon EC2 Images

This stuff rocks.  WowzaMediaServerPro allows us to run a RTMP server (think Flash Media Server) on Amazon Elastic Compute Cloud (EC2).  Pay as you stream... excellent business model for any businesses as you're not sure how many people will be using it (save on marketing/surveys etc), and you get a high-quality platform from the start rather than worrying about your VPS or dedicated hosting and opening firewalls left and right.

Now, because its using EC2 and you can ballpark the server's capacity depending on your client's applications, WowzaMedia said their streaming server can handle about 2000 concurrent streams.  Because I want high quality streams 100% (or 99.99999%) of the time, I decided that 1000 is my threshold.  What happens if we hit 1000?  With Amazon EC2, that's a piece of cake.

I built a Windows Service in .NET/C# that monitors all of my clients' WowzaMediaServerPro EC2 instances.  The Windows Service monitors them by checking the stream counts using Wowza's special URL, and stores it in a SQL database.  When the Flash client application requests a stream, it'll check the database via a Web Service for the stream count, and if it is over 1000 (my threshold), that prompts the Windows Service to send a command to create a new instance of the WowzaMediaServerPro EC2 server.  As soon the new instance is created, the Amazon EC2 service returns the new rtmp URL back to the database.  Hence, any subsequent conferences will be using the new rtmp URL.

That rtmp URL is pretty much dynamically loaded every time since the Windows Service also provides load balancing capabilities (to keep the # of streams level across various servers until it goes down a certain point) and it automagically terminates any unused servers (or when streams equals to 0).  You can use it to terminate the oldest first so you always have a "fresher" server running.

This is the ultimate geek stuff!! :-)

15 September 2008

Got a SSLSocketFactory cipher puzzle for you

That is if you're interested.

Am working on a .NET application that passes text streams back and forth with this Java server.  The Java server uses SSLSocketFactory along with the DH_anon_* cipher suites to handle encryption.  Right now, the .NET Framework does not even have the capabilities to connect to that Java server using the ciphers above...nor do I think it can handle anything.  I tried...  That really shows the maturity level of Java when compared to .NET! (I think that wasn't introduced in Java until v1.4.2, a couple of years ago)

So let's talk in code!  I need to create a socket server using SSLSocketFactory for testing.  Came across the KnockKnockServer example.  Javac'ed (compiled) the application and ran it on my machine using port 4444.  Ran the client java code against the server and that works.

My iteration of the Socket Server/Client using the SSLSocketFactory may be found at http://seerobcode.com/jsocket.zip

Now, how may I get .NET to read/understand the Java socket server?  I even tried the Mono.Security library to no avail.  Many pricey third-party apps that I have found do not even handle this.  Nothing works except for IKVM which works like a charm, however the DLL itself is 26MB and am not sure if it is worth 26MB for just a couple of lines of code?  I just want to find a lightweight library or a workaround entirely in .NET.

the Java Server code in a nutshell:

        SSLServerSocketFactory factory = (SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
        SSLServerSocket serverSocket = null;
        try {
            serverSocket = (SSLServerSocket)factory.createServerSocket(4444);

        } catch (Exception e) {
            System.err.println("Could not listen on port: 4444.");
            System.exit(1);
        }
        String[] dcsList = factory.getDefaultCipherSuites();
         System.out.println("   Default cipher suites:");
         for (int i=0; i<dcsList.length; i++) {
            System.out.println("      "+dcsList[i]);
         }
        String[] suites = serverSocket.getSupportedCipherSuites();
        serverSocket.setEnabledCipherSuites(suites);
        SSLSocket clientSocket = null;
        try {
            clientSocket = (SSLSocket)serverSocket.accept();           
        } catch (Exception e) {
            System.err.println("Accept failed.");
            System.exit(1);
        }
        clientSocket.startHandshake();
        ....

The .NET client side code ATTEMPT:

            const int bufSize = 4096;
            byte[] buf = new byte[bufSize];

            System.Net.Sockets.TcpClient _client = new System.Net.Sockets.TcpClient("localhost", 4444);
            Mono.Security.Protocol.Tls.SslClientStream scs = new Mono.Security.Protocol.Tls.SslClientStream(_client.GetStream(), "localhost", true, Mono.Security.Protocol.Tls.SecurityProtocolType.Tls);
            if (_client.Connected)
                Console.WriteLine("yay!");
            int x = scs.Read(buf, 0, bufSize);
            string s = Encoding.UTF8.GetString(buf, 0, x);
            Console.WriteLine(s);
            ....

At the .NET "int x..." it kept throwing "The authentication or decryption has failed." And the Java server threw "Exception in thread "main" javax.net.ssl.SSLHandshakeException: no cipher suites
in common ... "

My goal is to have .NET connect to the server and read the "Knock, knock" response.

Any ideas?

Edit 12/2/08:

Settled for a Rebex.Net.SecureSocket Library.  Rebex didn't have what I needed BUT their programmer, Lukas Pokorny, agreed to make it work in exchange for me purchasing one of their libraries.  I strongly encourage you to buy their libraries as their support is excellent!

My 25 days with Windows Mobile 6

[Edit: sorry its so late! It was intended for a May 2008 post]

As a Blackberry 7250 power user for the past 2 years.  I really use the data plan... no, I REALLY used it!  I started to drool at friends devices such as the 7305e and the 8830... faster downloads speeds and crisper displays.  Decided to do them one better and go after a Windows Mobile 6 device... compared the Smartphone and the SmartDevice.  Smartphones are shaped and acts like Blackberries and the SmartDevices has touch screens.  After reading one blog about the difference between the two and why Smartphones are better, I decided on a Sprint Motorola Q9c.

Boy it's a nightmare using Windows Mobile... the blasted thing kept crashing, apps moving so slowly, and very difficult to switch from one app to another.  It is not only switching applications, but you cannot copy-paste anything!  Not good.  (I hear Microsoft rectified that in WinMo 6.1)  Did find a third party application to do cut-pasting, but man, that should have been built outside of the box.  Email push? What's that in WinMo?  Non-existent just like in iPhones.

Blackberries rock!  I'm not a proud owner of the Curve 8330.  Rock-solid, small, crisp screen, unlimited data plan to go with PAM (phone as modem) so I can hook up my laptop to the cloud.  Awesome!!  And NOW RIM finally set up a program to encourage users to develop programs for it to head off Apple iPhone developer program.