public virtual async void connect(string address, SessionRequestListener networkListener, IDictionary <string, string> extraHeaders, string cookies, Proxy proxy, long timeout) { Uri uri = LsUtils.uri(address); string host = uri.Host; int port = LsUtils.port(uri); bool secure = LsUtils.isSSL(uri); try { string host4Netty = System.Net.Dns.GetHostAddresses(host)[0].ToString(); NettyFullAddress remoteAddress = new NettyFullAddress(secure, host4Netty, port, host, proxy); ExtendedNettyFullAddress extendedRemoteAddress = new ExtendedNettyFullAddress(remoteAddress, extraHeaders, cookies); WebSocketChannelPool wsPool = (WebSocketChannelPool)wsPoolManager.get(extendedRemoteAddress); IChannel ch = await wsPool.AcquireNewOr(timeout); if (ch != null) { if (ch.Active) { this.channel = new MyChannel(ch, wsPool, networkListener); WebSocketChannelHandler chHandler = new WebSocketChannelHandler(networkListener, channel); PipelineUtils.populateWSPipeline(ch, chHandler); networkListener.onOpen(); } else { log.Error("WebSocket handshake error, "); networkListener.onBroken(); } } else { log.Error("WebSocket handshake error, channel unexpectedly null"); networkListener.onBroken(); } } catch (Exception e) { log.Error("WebSocket handshake error: " + e.Message); networkListener.onBroken(); } }
public virtual void onBroken(string message, Exception cause) { lock (this) { // Debug.Assert(ch.EventLoop.InEventLoop); log.Error("Websocket write failed [" + ch.Id + "]: " + message, cause); close(); networkListener.onBroken(); } }