RejectedSoftware Forums

Sign up

Calling connectWebSocket twice fails

auto ws_url = URL("wss://");
auto ws = connectWebSocket(ws_url);
if ( !ws.connected )

ws_url = URL("wss://");
ws = connectWebSocket(ws_url);
if ( !ws.connected )

This is a minimized version of my case. The first connect is successful. But after second
connectWebSocket(ws_url); I sometimes recieve :

-object.Exception@../../.dub/packages/vibe-d-0.8.3/vibe-d/tls/vibe/stream/openssl.d(352): Reading from TLS stream was unsuccessful with ret 0

??:? [0x61bd6e]
??:? [0x621732]
exception.d:421 [0x47fbb3]
exception.d:388 [0x412fcd]
openssl.d:352 [0x564d33]
openssl.d:244 [0x565b9a]
openssl.d:239 [0x565b3d]
openssl.d:237 [0x5671c9]
interfaceproxy.d-mixin-302:302 [0x4b161e]
interfaceproxy.d-mixin-302:302 [0x4b19b9]
interfaceproxy.d-mixin-191:191 [0x4b0241]
operations.d:362 [0x4b1ec6]
operations.d:142 [0x4b1d3f]
smtp.d:56 [0x4b1c03]
smtp.d:41 [0x4af633]
client.d:908 [0x4bfe75]
client.d:908 [0x4bc850]
client.d:513 [0x4b9a2f]
websockets.d:120 [0x552e5a]
BinanceHelper.d:286 [0x49ffcf]

And sometimes I recieve another error :

core.exception.AssertError@../../.dub/packages/eventcore-0.8.34/eventcore/source/eventcore/drivers/posix/driver.d(302): Overwriting notification callback.

??:? [0x61bd6e]
??:? [0x621732]
??:? [0x61b2f1]
driver.d:302 [0x5c65a9]
sockets.d:351 [0x5cc131]
net.d:564 [0x5a7b97]
net.d:176 [0x5a7d32]
async.d:85 [0x5a6818]
net.d:569 [0x5a65c1]
net.d:538 [0x5a6411]
interfaceproxy.d-mixin-302:302 [0x4b0c07]
interfaceproxy.d-mixin-191:191 [0x4b02a1]
openssl.d:1131 [0x56af9d]
??:? BIO_read [0x7862faab]
??:? [0x78988809]
??:? [0x7898a0ac]
??:? [0x78986c63]
openssl.d:244 [0x565bf5]
openssl.d:244 [0x565b82]
openssl.d:239 [0x565b3d]
openssl.d:237 [0x5671c9]
interfaceproxy.d-mixin-302:302 [0x4b161e]
interfaceproxy.d-mixin-302:302 [0x4b19b9]
interfaceproxy.d-mixin-191:191 [0x4b0241]
client.d:542 [0x4bbd7a]
client.d:511 [0x4b9978]
websockets.d:120 [0x552e5a]
BinanceHelper.d:286 [0x49ffcf]

What I am missing here ? I really need to be able to two sockets at the same time.

Best Regards

Re: Calling connectWebSocket twice fails

I solved my problem by adding this function and calling it instead of connectWebSocket call.

	Returns a WebSocket client object that is connected to the specified host.
WebSocket simpleConnectWebSocket(URL url, const(HTTPClientSettings) settings = defaultSettings)
@safe {
	bool use_tls = (url.schema == "wss") ? true : false;
	url.schema = use_tls ? "https" : "http";

	/*scope*/auto rng = secureRNG();
	auto challengeKey = generateChallengeKey(rng);
	auto answerKey = computeAcceptKey(challengeKey);

	HTTPClientResponse res = requestHTTP(url,
		(scope req) {
			req.method = HTTPMethod.GET;
			req.headers["Upgrade"] = "websocket";
			req.headers["Connection"] = "Upgrade";
			req.headers["Sec-WebSocket-Version"] = "13";
			req.headers["Sec-WebSocket-Key"] = challengeKey;
	auto key = "sec-websocket-accept" in res.headers;
	enforce(key !is null, "Response is missing the Sec-WebSocket-Accept header.");
	enforce(*key == answerKey, "Response has wrong accept key");
	auto conn = res.switchProtocol("websocket");
	auto ws = new WebSocket(conn, null, rng);
	return ws;