Hi,
Is it possible to use the WebSocket implementation of vibe-d as a client?
Martin
Hi,
Is it possible to use the WebSocket implementation of vibe-d as a client?
Martin
On Mon, 28 Apr 2014 16:44:42 GMT, moechofe wrote:
Hi,
Is it possible to use the WebSocket implementation of vibe-d as a client?
Martin
I never tested it this way, but I think apart from making the initial HTTP request, the WebSocket
class should work in both directions. The main problem is that the HTTP client currently doesn't support protocol upgrades. Once that would be implemented (trivial), something like the following should work:
void connectWebSocket(HTTPMethod method, URL url, scope void delegate(scope WebSocket) del)
{
requestHTTP(method, url,
(scope req) {
req.headers["Upgrade"] = "websocket";
req.headers["Connection"] = "upgrade";
// TODO: use something like Base64.encode(generateRandomBytes()) instead
req.headers["Sec-WebSocket-Key" = "dGhlIHNhbXBsZSBub25jZQ==";
//req.headers["Sec-WebSocket-Protocol" = "someprotocol, someotherproto";
req.headers["Sec-WebSocket-Version" = "13";
//req.headers["Origin"] = "http://url/of/website/";
},
(scope res) {
// TODO: check response code etc. for errors
scope ws = new WebSocket(res.upgradeConnection(), null);
del(ws);
}
);
}