Hi, I am writting this network game and have come up with a little problem. I can telnet into the server application I made to correspond and can send it commands through a telnet client, and it will receive data from its own client. But for some reason the client refuses to acknowledge any data it receives from its own server despite the fact that there is an active connection and data is being sent.

I included the code below I think it causing the problem... None of the test messageboxes ever pop-up and nothing is ever added to the listbox.

I have no clue what is wrong because the same code has worked for me before.


 .ELSEIF uMsg==WM_CREATE


;invoke MessageBox,0,addr hostname,addr hostname,MB_OK

INVOKE socket,PF_INET,SOCK_STREAM,0
mov s1,eax
INVOKE inet_addr,offset hostname
.IF eax==INADDR_NONE
INVOKE gethostbyname,offset hostname
mov eax,[eax+12]
mov eax,[eax]
mov eax,[eax]
.ENDIF
mov sin1.sin_addr,eax
mov sin1.sin_family,AF_INET
INVOKE htons,23
mov sin1.sin_port,ax
INVOKE WSAAsyncSelect,s1,hWnd,WM_SOCKET,FD_CONNECT
INVOKE connect,s1,ADDR sin1,sizeof sin1

.ELSEIF uMsg==WM_SOCKET
mov eax,lParam
.IF ax==FD_CONNECT
shr eax,16
.IF AX==0
INVOKE WSAAsyncSelect,s1,hwnd,WM_SOCKET,FD_CLOSE or FD_READ
invoke MessageBox,0,0,0,MB_OK
.ENDIF

.ELSEIF ax==FD_ACCEPT
shr eax,16
.IF AX==0
INVOKE WSAAsyncSelect,s1,hwnd,WM_SOCKET,FD_CLOSE or FD_READ
invoke MessageBox,0,0,0,MB_OK
.ENDIF


.ENDIF

.ELSEIF ax==FD_CLOSE
shr eax,16
.IF AX==0
invoke MessageBox,0,0,0,MB_OK
.ENDIF

.ELSEIF ax==FD_READ
shr eax,16
.IF AX==0
invoke recv,s1,edi,1,0
invoke MessageBox,0,edi,edi,MB_OK
invoke lstrcmpi,edi,offset A
or eax,eax
jz AAA3
ret
AAA3: ; RECEIVING DATA
invoke recv,s1,ADDR Buffer,sizeOf Buffer,0
invoke SendMessage,hList,LB_ADDSTRING,0,addr Buffer
invoke CompareString,0,NORM_IGNORECASE,addr Buffer,-1,addr ONE,-1

.if eax == 2
invoke MessageBox,0,0,0,MB_OK
.endif


.ELSEIF ax==FD_WRITE
shr eax,16
.IF AX==0
ret
.ENDIF
.ENDIF
Posted on 2004-11-16 19:59:32 by Feuerfogel
you don't need to call WSAAsyncSelect each time.

.elseif uMsg == WM_CREATE

invoke WSAAsyncSelect,s1,hWnd,WM_SOCKET,FD_CONNECT or FD_CLOSE or FD_READ

.elseif uMsg == WM_SOCKET
mov eax,lParam
.if ax == FD_CONNECT
shr eax, 16 ; error code is in lParam`s high word
.if ax==NULL
; no error
.else
; error
.endif
.elseif ax == FD_READ
; same code here. etc.
Posted on 2004-11-17 06:57:36 by arafel
Thanks, that fixed the problem ... I was apparently wasn't declaring everything I needed for WSAAsyncSelect ...
Posted on 2004-11-17 12:46:38 by Feuerfogel
No, the problem was the WM_SOCKET handler at the very start of that code , as noted in the reply you received, you were NOT putting the error code in AX before your .if ax==fd_blah test - see what I mean?
You were checking the value of ax - and THEN putting the error code into ax - d'oh !! :P

It's great that your problem has been fixed, but it's important to understand exactly what was going wrong in the first place :)
Posted on 2004-11-17 15:40:07 by Homer