示例#1
0
        public void CloseSocket()
        {
            if (null == m_scH)
            {
                return;
            }


            lock (m_oLock)
            {
                m_scH.Shutdown(SocketShutdown.Both);
                m_scH.Close();
                m_scH = null;
                m_sdH = null;
                m_sIp = "";
                m_sPt = 0;

                m_sndC = NTC.OK;
                m_sndN = -1;
                for (int n = 0; n < m_sndB.Count; ++n)
                {
                    Array.Clear(m_sndB[n], 0, m_sndB[n].Length);
                }
            }

            if (null != m_pPrn)
            {
                TcpBase p = (TcpBase)m_pPrn;
                p.Query("Remove Client", this);
            }
        }
示例#2
0
        public int Create(TcpBase parent, string ip, int pt)
        {
            IPAddress ipAdd = null;

            m_pPrn = parent;
            m_sIp  = ip;
            m_sPt  = pt;

            if (null == m_sIp)
            {
                IPAddress[] vAdd
                    = Dns.GetHostEntry(Environment.MachineName).AddressList;

                ipAdd = vAdd[vAdd.Length - 1];
            }
            else
            {
                ipAdd = IPAddress.Parse(m_sIp);
            }

            m_sdH = new IPEndPoint(ipAdd, m_sPt);
            m_scH = new Socket(AddressFamily.InterNetwork
                               , SocketType.Stream
                               , ProtocolType.Tcp);

            return(NTC.OK);
        }
示例#3
0
        public void CloseSocket()
        {
            if (null == m_scH)
            {
                return;
            }


            lock (m_oLock)
            {
                m_arCon = null;
                m_arRcv = null;
                m_arSnd = null;

                m_scH.Shutdown(SocketShutdown.Both);
                m_scH.Close();
                m_scH = null;
                m_sdH = null;

                m_sIp = "";
                m_sPt = 0;
            }

            if (null != m_pPrn)
            {
                TcpBase p = (TcpBase)m_pPrn;
                p.Query("Remove Client", this);
            }
        }
示例#4
0
        public int Create(TcpBase parent, Socket scH, EndPoint sdH)
        {
            m_pPrn = parent;
            m_scH  = scH;
            m_sdH  = sdH;

            return(NTC.OK);
        }
示例#5
0
        override public int Query(string msg, object v)
        {
            if ("Remove Client" == msg)
            {
                TcpBase p = (TcpBase)v;
                RemoveClient(p);
            }

            return(NTC.EFAIL);
        }
示例#6
0
        public int Create(TcpBase parent, string ip, int pt)
        {
            IPAddress ipAdd = null;

            m_pPrn = parent;
            m_sIp  = ip;
            m_sPt  = pt;                                //System.Convert.ToInt32(pt);


            if (null == m_sIp)
            {
                //IPHostEntry	host	= Dns.GetHostEntry(Dns.GetHostName());
                //IPAddress[]	vAdd	= host.AddressList;

                IPAddress[] vAdd = Dns.GetHostEntry(Environment.MachineName)
                                   .AddressList;

                ipAdd = vAdd[vAdd.Length - 1];
            }
            else
            {
                ipAdd = IPAddress.Parse(m_sIp);
            }


            m_sdH = new IPEndPoint(ipAdd, m_sPt);
            m_scH = new Socket(AddressFamily.InterNetwork
                               , SocketType.Stream
                               , ProtocolType.Tcp);


            m_arCon = new SocketAsyncEventArgs();
            m_arRcv = new SocketAsyncEventArgs();
            m_arSnd = new SocketAsyncEventArgs();

            m_arCon.UserToken      = m_scH;
            m_arCon.RemoteEndPoint = m_sdH;
            m_arCon.Completed     += new EventHandler <SocketAsyncEventArgs>(IoComplete);

            m_arRcv.UserToken      = m_scH;
            m_arRcv.RemoteEndPoint = m_sdH;
            m_arRcv.Completed     += new EventHandler <SocketAsyncEventArgs>(IoComplete);
            m_arRcv.SetBuffer(new byte[NTC.PCK_MAX], 0, NTC.PCK_MAX);

            m_arSnd.UserToken      = m_scH;
            m_arSnd.RemoteEndPoint = m_sdH;
            m_arSnd.Completed     += new EventHandler <SocketAsyncEventArgs>(IoComplete);

            return(NTC.OK);
        }
示例#7
0
        protected void RemoveClient(TcpBase v)
        {
            int n = m_vCln.FindIndex(_cln => _cln.GetSocket() == v.GetSocket());

            if (0 > n)
            {
                return;
            }


            int key = m_vCln[n].NetId;

            m_vCln[n].Destroy();
            m_vCln.RemoveAt(n);

            System.Console.Write("Remove client[" + n + "]: " + key);
            System.Console.WriteLine(", Remain Client :" + m_vCln.Count);
        }
示例#8
0
        protected void RemoveClient(TcpBase v)
        {
            int n = m_vCln.FindIndex(_cln => _cln.GetSocket() == v.GetSocket());

            if (0 > n)
            {
                return;
            }


            uint key = m_vCln[n].NetId;

            m_vCln[n].Destroy();
            m_vCln.RemoveAt(n);

            PGLog.LOGI("RemoveClient::[" + n + "]: "
                       + key + ", Remain Client :" + m_vCln.Count);
        }
示例#9
0
        public int Create(TcpBase parent, Socket scH, EndPoint sdH)
        {
            bool hr = false;

            m_pPrn = parent;
            m_scH  = scH;
            m_sdH  = sdH;

            m_arRcv = new SocketAsyncEventArgs();
            m_arSnd = new SocketAsyncEventArgs();

            m_arRcv.UserToken      = m_scH;
            m_arRcv.RemoteEndPoint = m_sdH;
            m_arRcv.Completed     += new EventHandler <SocketAsyncEventArgs>(IoComplete);
            m_arRcv.SetBuffer(new byte[NTC.PCK_MAX], 0, NTC.PCK_MAX);

            m_arSnd.UserToken      = m_scH;
            m_arSnd.RemoteEndPoint = m_sdH;
            m_arSnd.Completed     += new EventHandler <SocketAsyncEventArgs>(IoComplete);

            hr = m_scH.ReceiveAsync(m_arRcv);

            return((false == hr)? NTC.EFAIL : NTC.OK);
        }