' Gambas class file Inherits SmtpSession Property Read Connected As Boolean Private $hSocket As New Socket Public Sub _new() 'Wait 10 seconds before timing out $hSocket.Timeout = 10000 $hSocket.EndOfLine = gb.Windows End Public Sub Client_Ready() 'Debug "Connected to remote host " & sSocket.Path End Public Sub Client_Closed() Debug "Connection Closed by foreign host." End Public Sub Client_Found() 'Debug "Host Found. Connecting..." End Public Sub Connect(hClient As SmtpClient, sHost As String, iPort As Integer) If Not sHost Then sHost = "localhost" If iPort = 0 Then iPort = 25 Super.Connect(hClient, sHost, iPort) $hSocket.Timeout = 10000 $hSocket.Connect(sHost, iPort) $hSocket.Blocking = True Me.Stream = $hSocket Do If $hSocket.Status = Net.Connected Or If $hSocket.Status <= 0 Then Break Wait 0.1 Loop If $hSocket.Status < 0 Then Select Case $hSocket.Status Case Net.CannotCreateSocket Error.Raise("Cannot create socket") Case Net.HostNotFound Error.Raise("Host not Found") Case Net.ConnectionRefused Error.Raise("Connection Refused") Case Net.CannotRead Error.Raise("Read error") Case Net.CannotWrite Error.Raise("Write error") End Select Endif End Public Sub Disconnect() Try $hSocket.Close End Private Function Connected_Read() As Boolean Return $hSocket.Status = Net.Connected End