Esempio n. 1
0
        public virtual void AsyncSend(NetworkData a_oData)
        {
            try
            {
                NetworkAction?.NetworkStateChanged(NetworkState.Sending, new StateObject(this, a_oData));

                NetworkSocket?.BeginSend(a_oData.Buffer, 0, a_oData.DataLength(true), SocketFlags.None, new AsyncCallback(SendCallback), this);
            }
            catch (Exception)
            {
                NetworkAction?.NetworkStateChanged(NetworkState.Error, new StateObject(this));
            }
        }
Esempio n. 2
0
        protected virtual void AcceptConnection()
        {
            try
            {
                NetworkAction?.NetworkStateChanged(NetworkState.Listening, new StateObject(this));

                m_oNetObject?.BeginAcceptTcpClient(new AsyncCallback(AcceptCallback), this);
            }
            catch (Exception e)
            {
                NetworkAction?.NetworkStateChanged(NetworkState.Error, new StateObject(this, e));
            }
        }
Esempio n. 3
0
        public virtual void AsyncReceive()
        {
            Data?.Clear();

            try
            {
                NetworkAction?.NetworkStateChanged(NetworkState.Receiving, new StateObject(this));

                NetworkSocket?.BeginReceive(Data.Buffer, 0, Data.BufferLength, SocketFlags.None, new AsyncCallback(ReceiveCallback), this);
            }
            catch (Exception)
            {
                NetworkAction?.NetworkStateChanged(NetworkState.Error, new StateObject(this));
            }
        }
Esempio n. 4
0
        public virtual StateObject SyncReceive()
        {
            try
            {
                Data?.Clear();

                NetworkSocket?.Receive(Data.Buffer, SocketFlags.None);

                return(new StateObject(this, Data));
            }
            catch (Exception)
            {
            }

            NetworkAction?.NetworkStateChanged(NetworkState.Error);

            return(null);
        }
Esempio n. 5
0
        public override void Establish()
        {
            if (IsConnected)
            {
                return;
            }

            try
            {
                m_oNetObject.BeginConnect(Address, Port, new AsyncCallback(ConnectCallback), this);

                NetworkAction?.NetworkStateChanged(NetworkState.Connecting, new StateObject(this));

                return;
            }
            catch (Exception)
            {
            }

            NetworkAction?.NetworkStateChanged(NetworkState.Error, new StateObject(this));
        }
Esempio n. 6
0
        public override void Establish()
        {
            if (IsConnected)
            {
                return;
            }

            try
            {
                m_oNetObject.Start();

                AcceptConnection();

                return;
            }
            catch (Exception)
            {
            }

            NetworkAction?.NetworkStateChanged(NetworkState.Error, new StateObject(this));
        }