Good day.
I wrote Vin.service, which with the help of the TcpListener class listens to port 25, intercepts mail and sends SMS. The situation is as follows: after we have received one message, the following are no longer intercepted. Can I close the client session incorrectly?
"OnStart":
Thread listen = new Thread(new ThreadStart(s.Listen)); listen.Start();
My SmtpHelper class:
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(); }
Next, StartProcessing ():
m_ConnectedIp = ParseIP_from_EndPoint(clientSocket.RemoteEndPoint.ToString()); m_ConnectedHostName = GetHostName(m_ConnectedIp); l.WriteEvent(String.Format("Клиент {0}: m_ConnectedIp = {1}, m_ConnectedHostName = {2}", _sessionId, m_ConnectedIp, m_ConnectedHostName)); _email.ip = m_ConnectedIp; _email.port = 25; if (clientSocket.Connected) { l.WriteEvent(">>>Socket connected"); } else { l.WriteEvent("<<<Socket NOT connected"); } SendData("220 " + System.Net.Dns.GetHostName() + " Service ready\r\n"); //РАБОТА С ВХОДНЫМИ ДАННЫМИ while (true) { //если есть данные, то считаем их if (clientSocket.Available > 0) { string lastCmd = ReadLine(); l.WriteEvent("lastCmd: " + lastCmd); //break; // добавил //парсим команду ProceedCommand(lastCmd); } }
Maybe what object should be closed? it turns out that after the first message was received, others are not caught.
Thank!