You don't need to send your reply from the event, just make Src a public
variable associated with this specific socket, and use SendTo later.  I
think your issue is trying to set a property, rather than actually
sending a packet. 

Angus


-------- Original Message --------

*Subject:* Re: [twsocket] Force UDP source port when sending
*From:* Dod <[EMAIL PROTECTED]>
*To:* ICS support mailing <twsocket@elists.org>
*Date:* Sat, 28 Jun 2008 18:06:32 +0200

Hello Angus,

Thank you, so I cannot force the port to same as listening but if I do
it  within  the  OnDataAvailable  then  the .SendTo will automatically
re-use  the same socket to send data back using same src port whenever
this port is actually used for listening by the server ?

So  this also mean that the OnDataAvailable procedure may take a while
to  get  outside if I need to do lenghtly operation. Is there a way to
"keep" this socket to re-use later ?

regards.


>> So question is : how to force UDP port source when sending it whenever
>> this port is used by a listener socket as the other application do ?
>> May be thru sockaddr_in structure ?

ARMSL> Yes, this is the (simplified) code from the ICS SNTP Time Server
that
ARMSL> responds to a UDP request with the time to the same IP and port. 

ARMSL> http://www.magsys.co.uk/download/software/sntp.zip

ARMSL> Angus


ARMSL> procedure TTimeServ.WUDPSocketDataAvailable(Sender: TObject;
Error:
ARMSL> Word);
ARMSL> var
ARMSL>     Buffer : array [0..1023] of char;
ARMSL>     Src    : TSockAddrIn;
ARMSL>     SrcLen : Integer;
ARMSL>     NewTime  : LongWord;
ARMSL>     DataPtr  : TWSocketData ;
ARMSL> begin
ARMSL>     SrcLen := SizeOf(Src);
ARMSL>     FWUDPSocket.ReceiveFrom(@Buffer, SizeOf(Buffer), Src, SrcLen);
ARMSL>     SrcIPAddr := Src ;
ARMSL>     NewTime := Trunc ((GetUTCTime - 2) * 24 * 60 * 60) ;
ARMSL>     ByteSwaps (@NewTime, SizeOf(NewTime)) ;
ARMSL>     DataPtr := @NewTime ;
ARMSL>     if FWUDPSocket.Sendto (Src, SrcLen, DataPtr, SizeOf(NewTime))
=
ARMSL>             SOCKET_ERROR then
TriggerQueryDone(FWUDPSocket.LastError);
ARMSL> end;


-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be





-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to