public void Connect(IPEndPoint ep) { state.SetConnecting(); Debug.WriteLine("KayakSocket: connecting to " + ep); this.socket = new SocketWrapper(ep.Address.AddressFamily); socket.BeginConnect(ep, iasr => { Debug.WriteLine("KayakSocket: connected to " + ep); Exception error = null; try { socket.EndConnect(iasr); } catch (Exception e) { error = e; } scheduler.Post(() => { if (error is ObjectDisposedException) { return; } if (error != null) { state.SetError(); Debug.WriteLine("KayakSocket: error while connecting to " + ep); RaiseError(error); } else { state.SetConnected(); Debug.WriteLine("KayakSocket: connected to " + ep); del.OnConnected(this); BeginRead(); } }); }); }
public void Connect(IPEndPoint ep) { state.SetConnecting(); Debug.WriteLine("KayakSocket: connecting to " + ep); this.socket = new SocketWrapper(ep.Address.AddressFamily); socket.BeginConnect(ep, iasr => { Debug.WriteLine("KayakSocket: connected to " + ep); Exception error = null; try { socket.EndConnect(iasr); } catch (Exception e) { error = e; } scheduler.Post(() => { if (error is ObjectDisposedException) return; if (error != null) { state.SetError(); Debug.WriteLine("KayakSocket: error while connecting to " + ep); RaiseError(error); } else { state.SetConnected(); Debug.WriteLine("KayakSocket: connected to " + ep); del.OnConnected(this); BeginRead(); } }); }); }