' // client socket connection
Type mSocketConnection(index As Long, _
inUse As Boolean, _
public_id As String, _
buffer_in As List, _
buffer_out As List, _
messages_in As List, _
sck As class_socket, _
profile As mUserProfile, _
RT As mSocketConnectionRT _
)
Private Sub srvListener_NewConnection(Successful As Boolean, NewSocket As Socket)
Dim x As Long
Dim ExistingClient As mSocketConnection
Dim NewClient As mSocketConnection
Dim freeSocket As Long
'srvListener.Close
Log(DateTime.Time(DateTime.Now) & " - srvListener_NewConnection (" & Successful & ") " & NewSocket.RemoteAddress)
If Successful Then
freeSocket = -1
For x = 0 To connections.Size - 1
ExistingClient = connections.get(x)
If Not(ExistingClient.InUse) Then
freeSocket = x
x = (connections.Size+1)
End If
Next
If freeSocket = -1 Then
' // add to the list
connections.Add(NewClient)
' // pointer to new list entry
freeSocket = (connections.Size-1)
Log(DateTime.Time(DateTime.Now) & " - srvListener_NewConnection (NEW) " & freeSocket)
' // initialise client connection
NewClient.Initialize
NewClient.sck.Initialize(Me, "Client", freeSocket)
' // initialise the user profile
NewClient.profile.Initialize
NewClient.profile.RESPONDER.Initialize
NewClient.profile.RESPONDER.Initialize
NewClient.profile.HW_SWITCH.Initialize
NewClient.profile.HW_LOC.Initialize
NewClient.profile.TEST_PROC.Initialize
' //assign it
ExistingClient = NewClient
Else
Log(DateTime.Time(DateTime.Now) & " - srvListener_NewConnection (EXISTING) " & freeSocket)
End If
' // flag this as being used
ExistingClient.inUse = True
' // this client object is either a new/ or recycled one
ExistingClient.sck.NewConnection(NewSocket)
Else
Log("Connection attempt failed: " & LastException.Message)
End If
srvListener.Listen
End Sub