Hello,

I've searched through the borad and read Iczelion and Wizard tuts but i'm trully stucked with this simple request to a website. Debugging my app, i can see that all is working find till 'recv' API. The program seems to be stopped when i'm reaching this API...doesn't know why. Sorry for the length of code:



;proto
UPDATE PROTO :HWND

.const
WINSOCK_VER equ 0002h ;winsock version required

.data
IP_ADDR db "66.102.11.99",0 ;google server address
wsaData WSADATA <?>
sockAddr sockaddr_in <?>
ERROR_VERSION_SOCKET db "You're version of Winsock isn't up to date, please upgrade wsock32.dll to ws2_32.dll",0
ERROR_CREATE_SOCKET db "Error creating socket...",0
ERROR_CONNECT db "Cannot connect to server !",0
ERROR_SEND db "Cannot send data to socket",0
GET db "GET / HTTP/1.1",0
ERROR_CLEANUP db "Cannot clean socket connection",0

.data?
hSocket dd ?
buffer_socket db 128d dup (?)

.code
UPDATE PROC uses EBX hWin:HWND

invoke WSAStartup,WINSOCK_VER, addr wsaData
test eax, eax
jz _startupSucceeded
;error handling code
mov ax, wsaData.wVersion
.if eax != 2
invoke MessageBoxEx,hWin, addr ERROR_VERSION_SOCKET, addr CAPTION,MB_ICONERROR+MB_OK,NULL
jmp _doCleanup
.endif

_startupSucceeded:

invoke socket, AF_INET, SOCK_STREAM, NULL
cmp eax, INVALID_SOCKET
jne _socket_created
; error handling code
invoke MessageBoxEx,hWin, addr ERROR_CREATE_SOCKET, addr CAPTION,MB_ICONERROR+MB_OK,NULL
jmp _doCleanup

_socket_created:
mov [hSocket], eax
mov [sockAddr.sin_family], AF_INET
invoke htons, 80
mov [sockAddr.sin_port], ax
invoke inet_addr, addr IP_ADDR
mov [sockAddr.sin_addr.S_un.S_addr], eax ;store IP

invoke connect,[hSocket],addr sockAddr, sizeof sockAddr
test eax, eax
jz _connectSucceeded
; error handling code
invoke MessageBoxEx,hWin,addr ERROR_CONNECT,addr CAPTION,MB_ICONERROR+MB_OK,NULL
jmp _doCleanup
_connectSucceeded:

; Send data
invoke send, [hSocket], addr GET, SIZEOF GET, NULL
cmp eax, SOCKET_ERROR
jne _sendSucceeded
; error handling code
invoke MessageBoxEx,hWin, addr ERROR_SEND, addr CAPTION,MB_ICONERROR+MB_OK,NULL
_sendSucceeded:

; Receive data
invoke recv, [hSocket], addr buffer_socket, sizeof buffer_socket, 0
test eax, eax
jz _doCleanup
cmp eax, SOCKET_ERROR
jne _recvSucceeded

; error handling code


_recvSucceeded:

jmp _connectSucceeded

_doCleanup:
invoke WSACleanup
test eax, eax
jz _cleanupSucceeded

; error handling code
invoke MessageBoxEx,hWin, addr ERROR_CLEANUP, addr CAPTION, MB_ICONERROR+ MB_OK,NULL
_cleanupSucceeded:

ret

UPDATE endp



I've tried to rewrite it, but i never get a response from the google server (that's all i want from now: having a response from the server...)

1) Do I have to switch my socket to "non blocked mode" ?

2) Is it right ? => GET db "GET / HTTP/1.1",0

3) Where is this damn problem ?

Thank you very much.
Posted on 2004-03-20 09:54:34 by Neitsa
The reason why the program seem to hang at recv is because you are using blocking mode. For your questions:

1) I do not think that is needed
2) I am not sure, never fooled with simple HTTP before. So sorry...
3) I think it is with the GET command you send. Perhaps you can log the packets that your browser send to the page etc or something like that.

Sorry if my reply did not help much..
Posted on 2004-03-20 10:17:42 by roticv
you need newlines in your GET statement - two of them (one to end the GET line, one for the required blank line to indicate you're done sending options). Furthermore, you should add the "Host" header item.

Have a look at, for example, http://www.asmcommunity.net/board/index.php?topic=5966 . You should probably take a look at the HTTP RFC, too.
Posted on 2004-03-20 10:19:17 by f0dder
Many thanks Roticv and Fodder,

I'll try to read this R.F.C and understand how the HTTP protcol works.


Thank you very much .

Regards, Neitsa.
Posted on 2004-03-20 10:48:29 by Neitsa