I'm having some problems with the winsock _ConnectionRequest event and would appreciate some one help. What I'm trying to do is, when the event is fired, to have a msgbox to accept or not the requested connection. Here is what I've done so far:
'**** part of the code extracted from www.Planet-Source-Code.com
' a new client connected
Private Sub sckListen_ConnectionReques
t(ByVal requestID As Long)
Dim strRemoteHost As String
Dim aFreeSocket As Integer
' Request the number of an unused socket
aFreeSocket = GetFreeSocket
If aFreeSocket = 0 Then
' Tell the new client that the server is full and close the connection
DebugText "Number of maximum clients reached ! A connection had to be refused!"
sckAccept(0).SendData "Sorry, server is full!"
If MsgBox("The following client " & sckAccept(aFreeSocket).Rem
oteHostIP & " is asking for a connection. Allow?", vbYesNo, "Connection Attempt) = vbYes Then
' accept the connection on a free socket. set status of this socket to true(used)
DebugText "A new Client with ID " & aFreeSocket & " and IP " & sckAccept(aFreeSocket).Rem
oteHostIP & " connected!"
' Send a welcome message to the new client
dData "Connection Accepted..."
' Refresh the combobox -> add our new client
' Tell the new client that the requested connection has been refused
sckAccept(0).SendData "Sorry, connection refused by the server!"
'***** code ends here!
The problem I have found is that until I the connection is not accepted there is no way to retrieve the RemoteHost. So when the msgbox is fired, since the connection has not been established yet the sckAccept(aFreeSocket).Rem
oteHostIP is an empty string...
"The following client is asking for a connection. Allow?" instead of
"The following client xxx.xxx.xxx is asking for a connection. Allow?"
Hope I explain myself. All help will be appreciated..
Thanks in advance