hi all, I duno what is wrong with my client,, it seem working but when I do the error checking,
the function "connect" always seem return -1(FFFFFFFFh).

can someone tell me wut is wrong??

thankx in adv,

here is my snippet code:

LOCAL SA_IN:sockaddr_in
LOCAL hConnect:DWORD


invoke WSAStartup, 101h, addr WSAdata
.IF (eax!=0)
;error initializing winsock lib
xor eax, eax
ret
.ENDIF

invoke socket, AF_INET, SOCK_STREAM, IPPROTO_IP
.IF (eax==INVALID_SOCKET)
;socket creation error
xor eax, eax
ret
.ENDIF
mov hConnect, eax

mov SA_IN.sin_family, AF_INET
invoke htons, Port
mov SA_IN.sin_port, ax
invoke inet_addr, addr szIP
mov SA_IN.sin_addr, eax

invoke connect, hConnect, addr SA_IN, SIZEOF SA_IN
this is the error occured, it seem always return -1(FFFFFFFFh)
.IF (eax==SOCKET_ERROR)
;error socket
.ENDIF
Posted on 2002-12-29 21:57:09 by Yanda
What about calling WSAGetLastError after the connect? That may give a better clue of whats wrong?
Posted on 2002-12-29 23:01:13 by japheth
hi, japheth

yes I did what u said, here is what I get for the error code:
WSAEWOULDBLOCK
(10035)
Resource temporarily unavailable.
This error is returned from operations on nonblocking sockets that cannot be completed immediately, for example recv when no data is queued to be read from the socket. It is a nonfatal error, and the operation should be retried later. It is normal for WSAEWOULDBLOCK to be reported as the result from calling connect on a nonblocking SOCK_STREAM socket, since some time must elapse for the connection to be established.
(from ms )

I did I test on the client,
I ran the client offlline and online , both return value is the same,,

so what is my problem here???
Posted on 2002-12-30 00:18:27 by Yanda
hi, maybe you not able to follow me, coz you haven;'t see my full code,,

so if I ignore the error reported by connect call, than the event "FD_ACCEPT" is notified, no matter my computer is connected to the internet or not. it always send FD_ACCEPT.......

please help me :(

here is my procedure:

ConnectProc proc hWnd:DWORD
LOCAL SA_IN:sockaddr_in
LOCAL hConnectEvent:DWORD, hConnect:DWORD
LOCAL WSAEventConnect:WSANETWORKEVENTS
LOCAL szTemp[256]:BYTE

invoke WSAStartup, 101h, addr WSAdata
.IF (eax!=0)
;error initializing winsock lib
xor eax, eax
ret
.ENDIF
invoke socket, AF_INET, SOCK_STREAM, IPPROTO_IP
.IF (eax==INVALID_SOCKET)
;socket creation error
xor eax, eax
ret
.ENDIF
mov hConnect, eax

mov SA_IN.sin_family, AF_INET
invoke htons, Port
mov SA_IN.sin_port, ax
invoke inet_addr, addr szIP
mov SA_IN.sin_addr, eax

invoke WSACreateEvent
mov hConnectEvent, eax
invoke WSAEventSelect, hConnect, hConnectEvent, FD_CONNECT+FD_READ+FD_WRITE+FD_CLOSE
;xcall MessageBox, NULL, "Connected to server!", "Connection", MB_OK
invoke connect, hConnect, addr SA_IN, SIZEOF SA_IN
.IF (eax==SOCKET_ERROR)
jmp @F
szacceptsockfailedERR db "Error: accept(sock) failed",13,10,"%d is the error.",0
@@:
invoke WSAGetLastError
invoke wsprintf, ADDR szTemp, ADDR szacceptsockfailedERR, eax
xcall MessageBox, NULL, addr szTemp, "Connection", MB_OK
.ENDIF

@CheckEventAgain:
invoke WSAWaitForMultipleEvents, 1, addr hConnectEvent, FALSE, INFINITE, FALSE
invoke WSAEnumNetworkEvents, hConnect, hConnectEvent, addr WSAEventConnect
;xcall MessageBox, NULL, "waiting", "Connection", MB_OK+MB_ICONERROR
test WSAEventConnect.lNetworkEvents, FD_CONNECT
jz @CheckRead
;do socket connect
xcall MessageBox, NULL, "Connected to server!", "Connection", MB_OK+MB_ICONERROR
@CheckRead:
test WSAEventConnect.lNetworkEvents, FD_READ
jz @CheckWrite
;do socket read
@CheckWrite:
test WSAEventConnect.lNetworkEvents, FD_WRITE
jz @CheckClose
;do socket write
@CheckClose:
test WSAEventConnect.lNetworkEvents, FD_CLOSE
jz @CheckEventAgain
;do socket close
xcall MessageBox, 0, "Disconnected from server!", "Connection", MB_OK+MB_ICONERROR
mov eax, 1
ret
ConnectProc endp
Posted on 2002-12-30 00:36:34 by Yanda
WSAEWOULDBLOCK isn't really an error. It's common for a winsock function to fail if the socket's in non-blocking mode. It just means the function would have to block to complete, which is not possible on a non-blocking socket.

For more info see http://tangentsoft.net/wskfaq/newbie.html#wouldblock

Thomas
Posted on 2002-12-30 03:34:08 by Thomas
When you recive the FD_CONNECT event (you will always recive that in non-blocking mode and with this event activated), you must check in the WSANETWORKEVENTS struct if there is an error.
Posted on 2002-12-30 14:30:09 by Kecol
hi, thx kecol and thomas,

okie, let me try to see if I can do the error checking myself...:stupid:


thankx in adv,
Posted on 2002-12-30 16:53:33 by Yanda
hi,
I did tried to check for the iErrorCode inside the WSANETWORKEVENTS struct,,

but I am not sure I did rite or not,, but I am sure its wrong because ,, the Connected messagebox never get called......

any help appreciated ^+^

thankx in adv,

here is what I did:

.................
test WSAEventConnect.lNetworkEvents, FD_CONNECT
jz @CheckRead
;do socket connect
xcall MessageBox, NULL, "Checking", "Connection", MB_OK+MB_ICONERROR
test WSAEventConnect.iErrorCode, 0
jz @F
this is never get called :(
xcall MessageBox, NULL, "Connected to server!", "Connection", MB_OK+MB_ICONERROR
@@:
................
Posted on 2002-12-31 02:25:48 by Yanda
Maybe:
test WSAEventConnect.iErrorCode, FD_CONNECT_BIT

jnz @F
Posted on 2002-12-31 02:47:55 by comrade
hi, that code doesn't work.

how do I make sure my client know what its doing?? like it try to connect to the server, and the server is not online, how do I make sure the client will report the message say "host not found"?? and also if the server is online and the client is trying to connect to it, how to make sure the client will also report the message say "Connected to host"???

just like a ftp client...

but the code I have provided last post, doesn't do that,,,
I did trid to check the FD_CONNECT event, and it does signaled when the connect call was made,, however the FD_CONNECT signal always signaled when the connect call was made , no matter when the server is online or offline. I was tring to check if the FD_CONNECT_BIT is 0 under the FD_CONNECT signal to see if the server is offline or online.


this drives me nutz,, coz I duno what is wrong, I have search google and this forum already.. no help was found.

so I am here to ask help again :(

please help me understand this better(the events)


thankx in adv,
Posted on 2003-01-01 12:33:23 by Yanda
iErrorCode is an array of words. The order of this words are this:
read event; #define FD_READ_BIT 0
write event; #define FD_WRITE_BIT 1
oob event; #define FD_OOB_BIT 2
accept event; #define FD_ACCEPT_BIT 3
connect event;#define FD_CONNECT_BIT 4 ;this is what you are looking for.
...and kip going.
example:
if you have edi pointing to the iErrorCode array
and you add to edi,(SIZEOF WORD*FD_CONNECT_BIT),
you will get edi pointing to the value (word) you are looking for.
Test if this word is 0. (you made the connection!!!)
Else, you have no connection and
the most probably thing is that you recive 10061. (connection refused)

I hope this help you.
Posted on 2003-01-02 00:49:32 by Kecol
thankx kecol,
let me try urs tomorrow,, too tired now,, just got from work,,

thankx alot,,


I might have more questions coming :(

hehe thankx in adv ^+^:stupid: :alright:
Posted on 2003-01-02 01:16:02 by Yanda
hi, kecol,

I followed your instruction, but doesn't seem to work,,,, maybe I did wrong,,

here is what I come up

lea edi, WSAEventConnect ;WSANETWORKEVENTS
add edi, 4 ;lNetWorkEvents
add edi, sizeof word*FD_CONNECT_BIT ;8
.IF (word ptr==0)
but this never get called no matter my server is online or offline......
xcall MessageBox, NULL, "Connected to server!", "Connection", MB_OK+MB_ICONERROR
.ENDIF
Posted on 2003-01-02 02:33:56 by Yanda
I have to say sorry about one important thing. The iErrorCode array is not of words. It's a dwords array. I made a litle program that shows the lNetworkEvents and iErrorCode values in the WSANETWORKEVENTS struct. This program does not show the way you must to program, but it shows that is posible what you are looking for.

Yanda, i really hope it help.
Posted on 2003-01-02 10:00:13 by Kecol
thankx kecol!

it solved my problem, and also help me learned something new!

thank you!
Posted on 2003-01-02 13:43:39 by Yanda