mcollina/mows — pull request #3 by ldstein (2013-11-13 10:20:40+00:00)
Title: Https

This patch is a resubmit of PR https://github.com/mcollina/mows/pull/2 minus all the weird commit issues I had earlier. It adds support for secure connections.

I have included updated unit tests for Node clients. Note I haven't included any browser-side tests. Not quite sure how to achieve this as the server relies on self-signed certificates. This requires the user to install/approve the certificate in their browser.

It includes a new method, createSecureServer:

```javascript

var clientHandler = function(client) {
// Handle client
}

var secureOpts = {
key: fs.readFileSync('./cert/my.webserver.com.key'),
cert: fs.readFileSync('./cert/my.webserver.com.cert')
}

mows.createSecureServer(secureOpts, clientHandler).listen(666);
```

To create a secure browser client, specify the 'wss' protocol:

```javascript
// ws is unsecure, wss is secure:
var unsecureClient = mows.createClient(665, 'ws://my.webserver.com');
var secureClient = mows.createClient(666, 'wss://my.webserver.com');
```

To create a secure Node client, define a protocol object and pass appropriate certificates, authentication options, etc:

```javascript

// See http://nodejs.org/api/https.html#https_https_request_options_callback
var secureClientOpts =
{
protocol:
{
ca: fs.readFileSync('./cert/24485013-my.webserver.com.cert')
}
};

var secureClient = mows.createClient(666, 'wss://my.webserver.com', secureClientOpts);
```