Ejemplo n.º 1
0
        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();
                    }
                });
            });
        }
Ejemplo n.º 2
0
        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();
                    }
                });
            });
        }