I have a problem with my Winsock code.
I am connecting via UDP to a machine on the local network. On this machine, there runs a third-party app, wich sends 4k of data as response, after I send a 11byte packet to it.
The code runs fine if I run it only one time, but fails if I call it in a loop with multiple IP's :(

EDIT: Well, it not just fails... it simply hangs after the "sendto" call. But it even doesnt return "SOCKET_ERROR" :confused:

Anyone knows what the error could be?

.if uMsg == WM_CREATE

invoke WSAStartup, 2h, addr wsa
.elseif uMsg == WM_DESTROY

call WSACleanup
GetServerData proc pIP :DWORD, pPort :DWORD

invoke RtlZeroMemory, addr szBuffer, 5120

invoke socket, AF_INET, SOCK_DGRAM, 0
mov nSocket, eax

mov sin.sin_family, AF_INET

invoke atodw, pPort
inc eax
invoke htons, eax
mov sin.sin_port, ax
invoke inet_addr, pIP
mov sin.sin_addr, eax
mov eax, sizeof sin
mov nRead, eax

invoke connect, nSocket, addr sin, sizeof sin

invoke sendto, nSocket, addr szStatus, 11, 0, addr sin, sizeof sin
invoke Sleep, 200
invoke recvfrom, nSocket, addr szBuffer, 5120, 0, addr sin, addr nRead
or eax, eax
jz @B

invoke closesocket, nSocket


GetServerData endp

Thanks in advance,
Posted on 2002-07-14 13:14:23 by bazik
The 'hang' is probably because recvfrom keeps returning 0 so your code jumps in a deadlock

I suggest you should register your socket with a window message with WSAAsyncSelect and handle the FD_READs instead of putting a Sleep between your sendto and recvfrom.

I hope it helps
Posted on 2002-07-14 15:17:41 by savage
Hmmm.... sounds like a good idea.
But it also hangs if I remove the loop :confused:

Anyway, I will try the FD_READ variante tomorrow....

Need to get some sleep now ;)
Posted on 2002-07-14 16:21:20 by bazik
Don't think this has anything to do with your problem but when using UDP connect just sets up a default remote host for the socket, an address specified in sendto will override the address given to connect so if your only going to your using sento and not send then using connect is unecesary.
Posted on 2002-07-14 17:35:42 by Kudos
if you beleive it or not, but this solved my problem!

I commented the "connect" line, and now it doesnt stall anymore!
At least with 3 entries... gonna test it with more now!

Thanks so far!
Posted on 2002-07-14 19:09:18 by bazik
i think you can leave out the closesocket as well
Posted on 2002-07-15 15:29:17 by savage