SMVS



  • I wrote the SVT server, but it's not working properly at what point: If I connect to him one time through the veal, he's... answer normal. (Figs 1-2) but if I am I'll get back on it. Through the other console cmd, I'll only show up black screen and everything.

    введите сюда описание изображения (Figure 1)

    введите сюда описание изображения (Figure 2)

    введите сюда описание изображения (Figure 3)

    In the last case, if I don't, there's nothing on the screen, and I don't even get my SVT.

    In the first case, my teams are displayed in consoles, they're the server, and I see an answer in this console (figure 4):

    введите сюда описание изображения (Figure 4)

    That's what I see, one client is connected to it, a server is working normally, and in all other cases it's not working correctly.Right?)

    That's how I implemented the SVT server.

     protected override void OnStart(string[] args)
            {
    SmtpHelper s = new SmtpHelper(this);
    System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(StartListen), (object)s );
    }
    

    void StartListen(object s)
    {
    try
    {
    var a = (SmtpHelper)s;
    a.Listen(); //запуск
    }
    catch (Exception ex)
    {
    l.Write("Error (StartListen(object s)): " + ex.ToString());
    throw;
    }

        }
    


    public void Listen()
    {
    try
    {
    SMTP_Listener = new TcpListener(IPAddress.Any, port);
    SMTP_Listener.Start();

                while (true)
                {
                    clientSocket = SMTP_Listener.AcceptSocket();
    
                    _sessionId = clientSocket.GetHashCode().ToString();
    
                    _email.sessionId = Convert.ToInt32(_sessionId);
    
    
                    StartProcessing(newController);
                    l.Write("we are there");
    
                   // System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(ClientThread), SMTP_Listener.AcceptTcpClient());
                }
    
            }
            catch (Exception ex)
            {
                l.Write("SMTP Listen Error: " + ex.ToString());
                throw;
            }
        }
    

    void StartProcessing(ClientSessionController newController)
    {

            try
            {
                m_ConnectedIp = ParseIP_from_EndPoint(clientSocket.RemoteEndPoint.ToString());
                m_ConnectedHostName = GetHostName(m_ConnectedIp);
    
                _email.ip = m_ConnectedIp;
                _email.port = 25;
    
    
                SendData("220 " + System.Net.Dns.GetHostName() + " Service ready\r\n");
    
                //if (!clientSocket.Connected)
                //    clientSocket.Connect(IPAddress.Any, port);
    
                //РАБОТА С ВХОДНЫМИ ДАННЫМИ
                while (true)
                {
                    //если есть данные, то считаем их
                    if (clientSocket.Available > 0)
                    {
                        //получение команды от клиента
                        string lastCmd = ReadLine();
    
                        //парсим команду от клиента (HELO, RCPT, DATA etc.)
                        if (lastCmd.Trim() != String.Empty)
                            ProceedCommand(lastCmd, newController);
                        //break;
                    }
                    else
                    {
                      //dump:  l.Write("[Socket isn't available now]");
                    }
                }               
            }
            catch (Exception ex)
            {
                throw;
            }
    
        }
    

    QUESTION:

    Can you please tell me how I can make my service equally serve all the clients involved, not just the first?



  • In such cases, there's usually one flow of a listener who's listening to the right port. When the client is connected, a new flow is created to service him directly and the listener is transferring work with the client to this flow. When the client completes the server, this flow is destroyed.

    Like that.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 1
  • 3
  • 2
  • 2
  • 2
  • 2
  • 2