You can do this without C-Code. I implement this feature in my BNetEx module. On Windows it looks like:
' Set socket to Non-Blocking mode
Local option : Int
option = True
ioctlsocket(socket, FIONBIO, Varptr(option))
' Connect
If connect(socket, address) = SOCKET_ERROR Then
If WSAGetLastError() <> WSAEWOULDBLOCK Then
' Any other error
EndIf
EndIf
' Check state
Local write : int
write = socket
Select select(0, Null, 1, Varptr(write), 0, Null, timeout)
Case SOCKET_ERROR
' Any other error
Case 0
' Server is not reachable
Default
' Connected to server
End Select
' Go into Blocking mode
option = False
ioctlsocket(socket, FIONBIO, Varptr(option))
(some pseudo code for select)
With this method you can realise a portscanner. It works correct but after 2 connection tests, WSAGetLastError return no WSAEWOULDBLOCK but WSAEINVAL ("The parameter s is a listening socket."). I dont know why, so I must close the socket and init a new socket for doing this *confused*
cu olli