ここではPythonの初心者です。asyncore と smtpd を使用して電子メール サーバーを作成しています。接続しているクライアントがソケットを閉じるタイミング/場合を検出する方法がわからないことを除いて、すべてが機能しているようです。また、非アクティブ後に自動的に接続を閉じるタイムアウトを設定できないようです。コード例を次に示します。CustomSTMPServer.handle_close は呼び出されません。そして、機能するタイムアウトを設定する方法がわかりません。どんな助けでも大歓迎です。
import smtpd
import asyncore
class CustomSMTPServer(smtpd.SMTPServer):
def handle_accept(self):
pair = self.accept()
if pair is None:
pass
conn, addr = pair
print 'Incoming connection from %s' % addr[0]
channel = smtpd.SMTPChannel(self, conn, addr)
def handle_close(self):
print 'Received close'
def process_message(self, peer, mailfrom, rcpttos, data):
print 'Receiving message from:', peer
print 'Message addressed from:', mailfrom
print 'Message addressed to :', rcpttos
print 'Message length :', len(data)
return
server = CustomSMTPServer(('127.0.0.1', 1025), None)
asyncore.loop()