Alaska Software Inc. - UDP with asinet
Username: Password:
AuthorTopic: UDP with asinet
maurilio longo UDP with asinet
on Wed, 25 Feb 2009 18:16:56 +0100
Hi all,

I'm writing a little applet which listens on a UDP port for incoming 
packets and answers back with a few bytes of information.

The applet is very little and more or less it does:

nSocket := SocketCreate( SOCK_DGRAM, 9000, INADDR_ANY, .F., @nError )
SocketSetBlockingMode( nSocket, .F. )

then it loops more or less like this:

while .t.
	nRead := SocketRecvFrom( nSocket, @cBuffer,, MSG_NORMAL, @aFrom, @nError )

	if nRead == 0
		if ( nEvent := AppeEvent( @mp1, @mp2, @oXbp, 1 ) ) <> xbe_None
			oXbp:handleEvent( ... )
		endif
	else
		 do some work with received data
		 then send answer
	endif
enddo

My problems are:

1) on a Windows 2003 server, if more than one terminal client is logged 
and has some xbase++ code running, even if a single one uses my code 
(which is inside a .dll), sometimes I receive the UDP datagram several 
seconds (up to 10 or 20) after it was sent from the client. It works 
like a charm if only a single instance of the xpp runtime is active (ie. 
I don't have other terminal clients logged in and using some other 
xbase++ code).

2) my code runs inside a thread which has no Xbp parts, but I have to 
call AppEvent() otherwise if another thread with Xbp Parts starts and 
stops (while my thread is running inside this process) it does not 
terminate (windows task manager shows that threads pile up until I close 
the whole process).

3) If I spend more time inside AppEvent(), using a higher timeout, 
problem 1) worsens, but I cannot spend less than 1 hundredth of a second.

I've read all messages inside asinet newsgroup but nobody seems to be 
using UDP.

So, question is, what am I doing wrong? I test error result of every 
SocketXXXX() call, there are no reported errors.

Any help really appreciated.

Maurilio Longo.