Esempio n. 1
0
 /// <summary>
 /// Handles the Connected event of the m_socketServer control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="SocketServer.SocketEventArgs"/> instance containing the event data.</param>
 void m_socketServer_Connected(object sender, SocketEventArgs e)
 {
     m_socketServer.SendMessage(String.Format(
                                    "204 Connected (Clients: {0} Version: {1} Build Date: {2})\r\n",
                                    m_socketServer.Count, VersionInfo,
                                    RetrieveLinkerTimestamp().ToShortDateString()), e.TcpClient);
 }
Esempio n. 2
0
        /// <summary>
        /// Handles the received commands of the m_socketServer control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">The <see cref="SocketServer.SocketEventArgs"/> instance containing the event data.</param>
        void m_socketServer_NewMessage(object sender, SocketEventArgs e)
        {
            OpResult opResult = new OpResult(OpStatusCode.BadRequest);

            try
            {
                if (e.Message.Length == 0)
                {
                    return;
                }

                if (e.Message.Equals("help", StringComparison.InvariantCultureIgnoreCase))
                {
                    opResult = m_remoteCommands.CommandList(GetPortNumber(m_basePortNumber));
                }
                else if (e.Message.Equals("exit", StringComparison.InvariantCultureIgnoreCase))
                {
                    m_socketServer.CloseClient(e.TcpClient);
                    return;
                }
                else
                {
                    string[] command = e.Message.Split(new char[] { ' ' }, 2);
                    if (command.Length == 0)
                    {
                        return;
                    }

                    opResult = m_remoteCommands.Execute(command[0], (command.Length == 2 ? command[1] : string.Empty));
                }
                m_socketServer.SendMessage(string.Format("{0} {1}\r\n", (int)opResult.StatusCode, opResult.StatusText), e.TcpClient);
                if (opResult.StatusCode == OpStatusCode.Ok)
                {
                    m_socketServer.SendMessage(opResult.ToString(), e.TcpClient);
                    m_socketServer.SendMessage(".\r\n", e.TcpClient);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Handles the received commands of the m_socketServer control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">The <see cref="SocketServer.SocketEventArgs"/> instance containing the event data.</param>
        void m_socketServer_NewMessage(object sender, SocketEventArgs e)
        {
            OpResult opResult = new OpResult(OpStatusCode.BadRequest);
            try
            {
                if (e.Message.Length == 0)
                    return;

                if (e.Message.Equals("help", StringComparison.InvariantCultureIgnoreCase))
                {
                    opResult = m_remoteCommands.CommandList(GetPortNumber(m_basePortNumber));
                }
                else if (e.Message.Equals("exit", StringComparison.InvariantCultureIgnoreCase))
                {
                    m_socketServer.CloseClient(e.TcpClient);
                    return;
                }
                else
                {
                    string[] command = e.Message.Split(new char[] { ' ' }, 2);
                    if (command.Length == 0)
                        return;

                    opResult = m_remoteCommands.Execute(command[0], (command.Length == 2 ? command[1] : string.Empty));
                }
                m_socketServer.SendMessage(string.Format("{0} {1}\r\n", (int)opResult.StatusCode, opResult.StatusText), e.TcpClient);
                if (opResult.StatusCode == OpStatusCode.Ok)
                {
                    m_socketServer.SendMessage(opResult.ToString(), e.TcpClient);
                    m_socketServer.SendMessage(".\r\n", e.TcpClient);
                }

            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Handles the Connected event of the m_socketServer control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="SocketServer.SocketEventArgs"/> instance containing the event data.</param>
 void m_socketServer_Connected(object sender, SocketEventArgs e)
 {
     m_socketServer.SendMessage(String.Format(
         "204 Connected (Clients: {0} Version: {1} Build Date: {2})\r\n",
         m_socketServer.Count, VersionInfo,
         RetrieveLinkerTimestamp().ToShortDateString()), e.TcpClient);
 }