public void Start()
        {
            Stop(false);

            if (_Listener == null)
            {
                try
                {
                    _Listener = new TcpListener(Configuration.LocalAddress, Configuration.ListenerPortNumber);
                    _CLI.Out("Listener created.");
                }
                catch (Exception e)
                {
                    _CLI.Out("Error while creating listener." + e.Message);
                }
            }

            if (_Listener != null)
            {
                try
                {
                    _Listener.Start();
                    _CLI.Out("Listening on " + Configuration.LocalAddress + ":" + Configuration.ListenerPortNumber);
                    _IsListening = true;
                    WaitForTcpClients();
                }
                catch (Exception e)
                {
                    _CLI.Out("Error while starting listener." + e.Message);
                }
            }
        }
Пример #2
0
        public static bool WriteToFile(string content, string filename, CommandLineInterface _CLI)
        {
            bool success = false;

            try
            {
                StreamWriter sw = new StreamWriter(@filename);
                sw.Write(content);
                sw.Close();
                success = true;
            } catch (Exception e)
            {
                _CLI.Out("Error while saving the file:" + e.Message, true, true);
            }
            return(success);
        }
Пример #3
0
        public async void StartHandling()
        {
            //Opening connection towards the client
            if (_CS == null)
            {
                try
                {
                    _CS = _Client.GetStream();

                    if (Configuration.IsDisplayConnections)
                    {
                        _CLI.Out("Client stream created. (Client ID: " + _ClientIdCounter.ToString() + ")");
                    }
                } catch (Exception e)
                {
                    _CLI.Out("Error. Client stream cannot be created. (Client ID: " + _ClientIdCounter.ToString() + ")");
                }
            }

            //Opening connection towards the webserver
            if (_CS != null)
            {
                try
                {
                    _WebServer = new TcpClient(Configuration.WebServerAddress.ToString(), Configuration.WebServerPortNumber);
                    _SS        = _WebServer.GetStream();

                    if (Configuration.IsDisplayConnections)
                    {
                        _CLI.Out("Server stream created. (Client ID: " + _ClientIdCounter.ToString() + ")");
                    }
                }
                catch (Exception e)
                {
                    _CLI.Out("Error. Server stream cannot be created. (Client ID: " + _ClientIdCounter.ToString() + ")");
                }
            }


            if (_CS != null && _SS != null)
            {
                ContinueReadWrite = true;
                StartReadWrite();
                _HeartBeat.Start();
            }
        }