A Demonstration of the ServerSocket API in AIR 2

In order to validate the new ServerSocket APIs in AIR 2, I wrote an application called HTTPeek. HTTPeek is a proxy server that sits between your browser and the network, and can show you HTTP request and response headers. It can handle compressed content, chunked content, binary content, etc. Check out the video below to see it in action:

Most of the HTTPeek code is dedicated to implementing just enough of the HTTP protocol to be an effective proxy, but the socket portion of the code is actually not all that complex. And the creation of the ServerSocket itself is very simple. The function below gets called when the user clicks on the "Listen" button:

private function onListen():void{this.sockets = new Array();this.server = new ServerSocket();this.server.addEventListener(Event.CONNECT, onConnect);try{this.server.bind(Number(this.portNumber.text), String(this.interfaces.value));this.server.listen();this.listenButton.label = "Close";}catch (e:Error){Alert.show(e.message, "Error", Alert.OK);return;}this.debugButton.enabled = true;}

HTTPeek is open-source and hosted here on Google Code. Feel free to check out the source to see how it works.