does anyone know how i can tell when a socket failed to connect,
ie connect() tried to connect, but could not find host or somethin
on non-blocking sockets
i know it posts a message to WM_SOCKET but not sure what lParam is
Posted on 2004-04-26 08:02:08 by someone
the following link explains what happens when you get error with the connect api:

MSDN CONNECT

additional benificial links:

Iczelions Tutorial

Thomas' Tutorial
Posted on 2004-04-26 09:54:34 by smurf
i've already looked at that stuff, and it doesn't explain what message is posted when connection failed, it explains a successful connection, or if the api failed, but it doesn't explain what happens if the host could not be connected to. (on non-blocking sockets)
Posted on 2004-04-27 05:47:16 by someone
hm, on non-blocking sockets...
isn't that, when the connect-api failed, the connection failed? as it doesn't wait for the action, the api just fails. afaik, you have to check the timeouts as well (say, wait some time for the connection to be established)
Posted on 2004-04-27 13:20:54 by hartyl
Are you using WSAGetLastError after an error to find out what's wrong?

invoke connect,Sock,addr sin,sizeof sin
.if eax==SOCKET_ERROR
invoke WSAGetLastError
; Other error stuff was here
.else
.endif ;connect

Regards, P1 :cool:
Posted on 2004-04-27 13:22:03 by Pone
hey, thanx for replying everybody
but i still can't get it working

i do check WSAGetLastError, after connect, but that'll only return whether the api succeded, which it does, but the connection doesn't.
i worked out that it posts the FD_CONNECT message in a lo-word hi-word thing, so now i just gotta work out how to find the other part of it
so new question, how do i find the low and hi words of a dword (i think thats what i needa know)
Posted on 2004-04-28 03:28:19 by someone
here we connect using non-blocking socket:
invoke connect,hSocket,ADDR sin,sizeof sin

now we check to see if a connection has been established:

.elseif uMsg == EVENT ;your special notification event you made when you used the WSAAsyncSelect api
mov eax, lParam
.if ax == FD_CONNECT
;//we know here if a connection is actually made. if the connection is made you can then send a command. check out the following link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/wsaasyncselect_2.asp

post your source code for faster results and i will take a look to see what you are doing wrong. also im sorry dont have too much time to go into details here.

aslo if you move lParm into eax the FD_CONNECT will be located in ax like the above listed code.
Posted on 2004-04-28 03:49:22 by smurf
hey
thats not the problem, i can establish a connection, and send data and all that, the only thing i'm having trouble with is what is posted when the connection could not be established.

for example, when i establish a successful connection (assuming eax is lParam)
(eax==FD_CONNECT) (ax==FD_CONNECT)

but if it could not connect, then
(eax!=FD_CONNECT) (ax==FD_CONNECT.)

so FD_CONNECT is the loword(or hi-word ?) of both connected and could-not-connect.
and if the connection was successful then the hi-word was null, otherwise what was it, because it's not null ?

i hope i'm making some sense, i'd post some code, but it wouldn't help in this situation.
thanks
Posted on 2004-04-28 04:06:36 by someone
Hi,
I think u should check if the wParam of your custom mesage is NULL. If it is null, there are no errors, or else, something went wrong:alright:

Thomas Antony
Posted on 2004-04-28 04:19:21 by thomasantony
hey, nope wParam contains the socket id
Posted on 2004-04-28 04:21:38 by someone
PSDK:

The high word of lParam contains any error code.
Posted on 2004-04-28 07:13:01 by Aaro
hey, but how do i find out the high word
Posted on 2004-04-28 08:36:39 by someone

does anyone know how i can tell when a socket failed to connect,
ie connect() tried to connect, but could not find host or somethin
on non-blocking sockets
i know it posts a message to WM_SOCKET but not sure what lParam is


hey
thats not the problem, i can establish a connection, and send data and all that, the only thing i'm having trouble with is what is posted when the connection could not be established.


What changed? I know your sending us down a different direction.

Regards, P1 :cool:
Posted on 2004-04-28 08:55:49 by Pone


mov eax, [lparam]
shr eax, 16
Posted on 2004-04-28 08:59:40 by roticv
hey
thanks roticv i got it working now
pone --> i meant the connection timed out, not the api failed
thanks
Posted on 2004-04-28 09:20:51 by someone
actually dont bother with the hi or low word. your FD_CONNECT value will be found in eax.
   .elseif uMsg == EVENT

mov eax, lParam
.if eax == FD_CONNECT

If the client uses the functions WSAAsyncSelect or WSAEventSelect, the notification is announced with FD_CONNECT and the error code associated with the FD_CONNECT indicates either success or a specific reason for failure.

so basically after you use the connect api you will automatically receive an FD_CONNECT message whether you actually connect or not. you will need to check the FD_CONNECT notification to see if there were any error messages sent with it. the following are the possible error codes for FD_CONNECT:

Error code Meaning:

WSAEAFNOSUPPORT - Addresses in the specified family cannot be used with this socket.
WSAECONNREFUSED - The attempt to connect was forcefully rejected.
WSAENETUNREACH - The network cannot be reached from this host at this time.
WSAEFAULT- The namelen parameter is incorrect.
WSAEINVAL - The socket is already bound to an address.
WSAEISCONN - The socket is already connected.
WSAEMFILE - No more file descriptors are available.
WSAENOBUFS - No buffer space is available. The socket cannot be connected.
WSAENOTCONN - The socket is not connected.
WSAETIMEDOUT - Attempt to connect timed out without establishing a connection.
This error code is extracted from the lParam in the reply message using the WSAGETSELECTERROR macro.

you will need to use the macro to get the error code after the FD_CONNECT notification is received. ive never used this macro before so you will need to set it up yourself.

another option to check for failure according to the msdn docs is to use the select function to see if the socket is writeable.
Use the select function to determine the completion of the connection request by checking to see if the socket is writeable.
Posted on 2004-04-28 09:39:37 by smurf
That macro just extarcts the hi word of lparam...


.elseif [uMsg] == EVENT
mov eax, [lParam]
.if ax == FD_CONNECT
shr eax, 16
.if ax != 0
!!!ERROR!!! Error number in ax
.endif
Posted on 2004-04-28 17:47:32 by Aaro
hi, thanks everyone for the replies
i got it workin now, by checking the hi-word of lParam
i was originally checking eax (lParam) for FD_CONNECT, but if an error occured, only the lo-word contains FD_CONNECT, and the hi-word contains the error message.
anyway it's all good now, so thanks again
Posted on 2004-04-29 07:13:24 by someone
I didnt see anywhere in the msdn indicating that FD_CONNECT would be found in the lo word. Ive been working with winsock functions lately and this info is good to know.
Posted on 2004-04-29 10:34:26 by smurf