Hello Everyone !
How do I detect which socket has been disconnected?
my code :
How do I detect which socket has been disconnected?
my code :
B4X:
Sub Class_Globals
Dim AStreams As AsyncStreams
Dim Server As ServerSocket
Dim Socket1 As Socket
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
Server.Initialize(5500, "Server")
Server.Listen
Log("MyIp = " & Server.GetMyIP)
End Sub
Sub Server_NewConnection (Successful As Boolean, NewSocket As Socket)
If Successful Then
Socket1 = NewSocket
Log(Socket1)
'Can only use prefix mode if both sides of the connection implement the prefix protocol!!!
AStreams.InitializePrefix(Socket1.InputStream, False, Socket1.OutputStream, "AStreams")
Else
Log(LastException.Message)
End If
Server.Listen
End Sub
Sub AStreams_NewData (Buffer() As Byte)
Dim msg As String
msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
Log(msg)
End Sub
Sub AStreams_Error
Log(LastException.Message)
Log("AStreams_Error")
End Sub
Sub AStreams_Terminated
Log("AStreams_Terminated")
' HOW CAN I GET THE DISCONNECTED SOCKET ?
End Sub