[Delivery-boy-cvs] client/DeliveryBoyC/classes clsEasyTCPServer.cs,1.5,1.6
Status: Planning
Brought to you by:
mkloubert
From: Marcel K. <gen...@us...> - 2005-03-05 10:29:58
|
Update of /cvsroot/delivery-boy/client/DeliveryBoyC/classes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12929/DeliveryBoyC/classes Modified Files: clsEasyTCPServer.cs Log Message: - clsEasyTCPServer class now works Index: clsEasyTCPServer.cs =================================================================== RCS file: /cvsroot/delivery-boy/client/DeliveryBoyC/classes/clsEasyTCPServer.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** clsEasyTCPServer.cs 13 Feb 2005 16:46:53 -0000 1.5 --- clsEasyTCPServer.cs 5 Mar 2005 10:29:43 -0000 1.6 *************** *** 45,48 **** --- 45,51 ---- * \note * $Log$ + * Revision 1.6 2005/03/05 10:29:43 generalpd + * - clsEasyTCPServer class now works + * * Revision 1.5 2005/02/13 16:46:53 generalpd * - moved application run code to seperate method Run() *************** *** 85,89 **** /// Connections ! private ArrayList m_oConnections = null; /// Accept-Event-Handler-Struct --- 88,92 ---- /// Connections ! private clsEasySocket[] m_oConnections; /// Accept-Event-Handler-Struct *************** *** 91,94 **** --- 94,101 ---- /// Accept-Event-Handler public event AcceptHandler OnAccept; + /// Receive-Event-Handler-Struct + public delegate void ReceiveHandler(System.Object sender, clsEasySocket socket, System.Byte[] buffer, System.Int32 bytes_read); + /// Receive-Event-Handler + public event ReceiveHandler OnReceive; /*! \fn public clsEasyTCPServer *************** *** 103,108 **** //ListenQueue = m_oListenSocket.ListenQueue; MaxConnections = 0; - - m_oConnections = new ArrayList(); } --- 110,113 ---- *************** *** 118,142 **** get { ! Int32 i = 0; ! ArrayList oBuffer = new ArrayList(); ! ! clsEasySocket oSocketBuffer = null; ! ! for (i = 0; i < m_oConnections.Count; i++) ! { ! oSocketBuffer = (clsEasySocket)m_oConnections[i]; ! ! if ( oSocketBuffer.Connected ) ! oBuffer.Add(oSocketBuffer); ! } ! ! m_oConnections = oBuffer; ! ! // create a new temporary array and copy all stuff from the ArrayList to the temp array ! // for return ! clsEasySocket[] o_es_buffer = new clsEasySocket[m_oConnections.Count]; ! oBuffer.CopyTo(o_es_buffer); ! ! return o_es_buffer; } } --- 123,127 ---- get { ! return m_oConnections; } } *************** *** 158,162 **** set { ! m_ui32MaxConnections = value; } } --- 143,154 ---- set { ! int i = 0; ! ! m_ui32MaxConnections = value; ! ! m_oConnections = new clsEasySocket[m_ui32MaxConnections]; ! ! for (i = 0; i < m_oConnections.GetLength(0); i++) ! m_oConnections[i] = new clsEasySocket(); } } *************** *** 264,268 **** // init timer and start it ! m_oTimer = new Timer(250); m_oTimer.Elapsed += new ElapsedEventHandler(this.TimerElapsed); m_oTimer.Start(); --- 256,260 ---- // init timer and start it ! m_oTimer = new Timer(125); m_oTimer.Elapsed += new ElapsedEventHandler(this.TimerElapsed); m_oTimer.Start(); *************** *** 332,335 **** --- 324,329 ---- if (m_oListenSocket.Pending()) { + int i = 0; + bool boolIsFull = true; Socket s = m_oListenSocket.AcceptSocket(); *************** *** 338,347 **** if (s.Connected) ! m_oConnections.Add( new clsEasySocket(s) ); ! Console.WriteLine(m_oConnections.Count.ToString()); } return; } } --- 332,371 ---- if (s.Connected) ! { ! for (i = 0; i < m_oConnections.GetLength(0); i++) ! { ! if (!m_oConnections[i].Connected) ! { ! m_oConnections[i] = new clsEasySocket(s); ! m_oConnections[i].OnReceive += new clsEasySocket.ReceiveHandler(ReceiveData); ! boolIsFull = false; ! break; ! } ! } ! ! if (boolIsFull) ! s.Close(); ! } } return; } + + /*! \fn private void ReceiveData (System.Object sender, System.Byte[] buffer, System.Int32 bytes_read); + * \brief Data ready for read + * + * \param sender This timer instance + * \param buffer Data + * \param bytes_read # of bytes that are ready for reading + * + * \return (none) + */ + private void ReceiveData (System.Object sender, System.Byte[] buffer, System.Int32 bytes_read) + { + if (null != OnReceive) + OnReceive(this, (clsEasySocket)sender, buffer, bytes_read); + + return; + } } |