Re: [twsocket] Force UDP source port when sending
> What could be the difference between NT4 SP6 and XP/Vista > Winsock layer that would produce this "bind error address already > in use" ??? Sorry, no idea, I do still have an NT4 server, but it's not been powered for a few years. I never really did much on NT4, went straight from Win9x to W2K. I'm sure there's a disclaimer somewhere about ICS not working on NT4, it's probably using a very old winsock version. Windows 2000 server is reliable, and I can see us supporting that for another 10 years...although I did finally update my own main server to W2K3 earlier this year. Angus -- 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
Re: [twsocket] Force UDP source port when sending
Hello Angus, Just for experience, I tried with my old "bad" TWSocketServer way of use, and get the bind error under Vista/XP too, so your advices has been very helpfull as I can now make it work under Vista/XP, but I need to make it work on NT4 :-( regards. -- 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
Re: [twsocket] Force UDP source port when sending
Hello Angus, Tested on XP ... works too. The "original" program that I must replace (and don't have the sources) works on the NT4 machine so there must be something to do. What could be the difference between NT4 SP6 and XP/Vista Winsock layer that would produce this "bind error address already in use" ??? I hate when I have to work on outdated machines :-( Regards. -- 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
Re: [twsocket] Force UDP source port when sending
Hello Angus, I just tested it on a Vista machine and it works, no bind error, back to the "original" NT4 machine (I know its old but we still use some NT4 servers that work perfectly) and I get bind error ?!? regards. -- 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
Re: [twsocket] Force UDP source port when sending
> May be I need to do something more if I .SendTo outside > OnDataAvailable ? I would have thought not, but make sure the public variable is not being corrupted by another received packet meanwhile, it should be kept for the FIFO queue. I use SendTo in my IP Logger component, which will send and receive UDP and TCP packets. I've just run the demo on two PCs, each listening and sending on port , sending packets to each other. Not exactly the same as your application, but almost. http://www.magsys.co.uk/download/software/magiplog11.zip Angus -- 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
Re: [twsocket] Force UDP source port when sending
Hello Angus, Still not working but I found something, if I do a .SendTo inside the OnDataAvailable after the .ReceiveFrom, it works, no bind error, but in my program I have to pass the received data to some worker queue that take some seconds to produce the answer and then when it tries to .SendToitproducethe error. I tried to save the SrcSocket(sockaddr_in) from the .ReceiveFrom to reuse it with .SendTo but without success, still bond error. May be I need to do something more if I .SendTo outside OnDataAvailable ? regards. >> And he used TWSocketServer >> and since then I always used the same way too. ARMSL> No idea how that worked, maybe the client was using a different port to ARMSL> reply. >> TMySocketServer ARMSL> If you have been making use of the TSocketServer client to save ARMSL> application data for the reply, you'll need a rethink. Perhaps a FIFO ARMSL> queue, I think there's a TList descendent that does that in modern Delphi ARMSL> versions. With UDP there's always a risk of lost packets, if your ARMSL> transmit conflicts with a new received packet, or at least that's my ARMSL> minimal understanding of UDP. ARMSL> Angus -- 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
Re: [twsocket] Force UDP source port when sending
Hello Hoby, I know about it, each TCP has an order number that is re-ordered by the socket layer so it reach ICS well ordered, I never used UDP for more than one-packet transmission protocol like Radius or NTP. regards. HS> Hello Dod... HS> Just to be clear about UDP behavior... This only worked because your HS> transmission pattern is based on a single packet exchange. That pattern HS> basically results in a virtual ack/nack process, which orders data by HS> default. UDP is not only unreliable, it is also inherently UNORDERED. So, HS> it is possible that packets could appear out of order, if you were sending HS> multi-packet bursts. This requires you to provide for orderly logic as well. HS> Hence, the queue of some type. HS> IMHO... If you need orderly, reliable transmissions... use TCP. The speed HS> benefit of UDP is only valuable for single packet exchanges. Otherwise, the HS> robust TCP overhead is much better than anything I can provide instead. HS> Regards... HS> Hoby HS> -Original Message- HS> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On HS> Behalf Of Dod HS> Sent: Wednesday, July 02, 2008 5:35 AM HS> To: ICS support mailing HS> Subject: Re: [twsocket] Force UDP source port when sending HS> Hello Angus, ARMSL>> No idea how that worked, maybe the client was using a different port HS> to ARMSL>> reply. HS> Absolutely, my other programs never needed to re-use same src port so HS> I never got the problem. ARMSL>> If you have been making use of the TSocketServer client to save ARMSL>> application data for the reply, you'll need a rethink. Perhaps a HS> FIFO ARMSL>> queue, I think there's a TList descendent that does that in modern HS> Delphi ARMSL>> versions. With UDP there's always a risk of lost packets, if your ARMSL>> transmit conflicts with a new received packet, or at least that's my ARMSL>> minimal understanding of UDP. HS> UDP packet lost happend as they are sent and without any SYN/ACK HS> dialog between src and dest so UDP is fast but you have to manage HS> packet acknowledge yourself to not loose data. For my application I HS> only receive one packet and send one packet back. HS> regards. HS> -- HS> To unsubscribe or change your settings for TWSocket mailing list HS> please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket HS> 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
Re: [twsocket] Force UDP source port when sending
Hello Dod... Just to be clear about UDP behavior... This only worked because your transmission pattern is based on a single packet exchange. That pattern basically results in a virtual ack/nack process, which orders data by default. UDP is not only unreliable, it is also inherently UNORDERED. So, it is possible that packets could appear out of order, if you were sending multi-packet bursts. This requires you to provide for orderly logic as well. Hence, the queue of some type. IMHO... If you need orderly, reliable transmissions... use TCP. The speed benefit of UDP is only valuable for single packet exchanges. Otherwise, the robust TCP overhead is much better than anything I can provide instead. Regards... Hoby -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dod Sent: Wednesday, July 02, 2008 5:35 AM To: ICS support mailing Subject: Re: [twsocket] Force UDP source port when sending Hello Angus, ARMSL> No idea how that worked, maybe the client was using a different port to ARMSL> reply. Absolutely, my other programs never needed to re-use same src port so I never got the problem. ARMSL> If you have been making use of the TSocketServer client to save ARMSL> application data for the reply, you'll need a rethink. Perhaps a FIFO ARMSL> queue, I think there's a TList descendent that does that in modern Delphi ARMSL> versions. With UDP there's always a risk of lost packets, if your ARMSL> transmit conflicts with a new received packet, or at least that's my ARMSL> minimal understanding of UDP. UDP packet lost happend as they are sent and without any SYN/ACK dialog between src and dest so UDP is fast but you have to manage packet acknowledge yourself to not loose data. For my application I only receive one packet and send one packet back. regards. -- 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
Re: [twsocket] Force UDP source port when sending
Hello Angus, ARMSL> No idea how that worked, maybe the client was using a different port to ARMSL> reply. Absolutely, my other programs never needed to re-use same src port so I never got the problem. ARMSL> If you have been making use of the TSocketServer client to save ARMSL> application data for the reply, you'll need a rethink. Perhaps a FIFO ARMSL> queue, I think there's a TList descendent that does that in modern Delphi ARMSL> versions. With UDP there's always a risk of lost packets, if your ARMSL> transmit conflicts with a new received packet, or at least that's my ARMSL> minimal understanding of UDP. UDP packet lost happend as they are sent and without any SYN/ACK dialog between src and dest so UDP is fast but you have to manage packet acknowledge yourself to not loose data. For my application I only receive one packet and send one packet back. regards. -- 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
Re: [twsocket] Force UDP source port when sending
> And he used TWSocketServer > and since then I always used the same way too. No idea how that worked, maybe the client was using a different port to reply. > TMySocketServer If you have been making use of the TSocketServer client to save application data for the reply, you'll need a rethink. Perhaps a FIFO queue, I think there's a TList descendent that does that in modern Delphi versions. With UDP there's always a risk of lost packets, if your transmit conflicts with a new received packet, or at least that's my minimal understanding of UDP. Angus -- 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
Re: [twsocket] Force UDP source port when sending
Hello Angus, OK now I understand, I'll try this immediately. I remember my very first UDP application (I already made some without any problem) that was based on "User Made" ICS's website section called "ICS NetFind" from Sven Schmidts. And he used TWSocketServer and since then I always used the same way too. I don't remember having read any information about this in any ICS documentation/FAQ but thank you for this explanation that is important to keep in mind. regards. ARMSL> No!! ARMSL> TSocketServer is designed for TCP, not UDP, it listens on a port for a ARMSL> new connection then transfers that connection to a new socket for each ARMSL> client. ARMSL> UDP is connectionless and only supports one client at a time, so there is ARMSL> no need for a new socket for each client, you just reply using the ARMSL> listening TWSocket. ARMSL> This probably explains all your problems, TSocketServer is still using ARMSL> the listening socket, but you trying to reply on a different socket. You ARMSL> need to removed TSocketServer from the project, replace it with TWSocket ARMSL> and sanity should prevail. ARMSL> Angus -- 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
Re: [twsocket] Force UDP source port when sending
> I have a SocketServer because it's the way to make a listening > UDP server isn't it ? No!! TSocketServer is designed for TCP, not UDP, it listens on a port for a new connection then transfers that connection to a new socket for each client. UDP is connectionless and only supports one client at a time, so there is no need for a new socket for each client, you just reply using the listening TWSocket. This probably explains all your problems, TSocketServer is still using the listening socket, but you trying to reply on a different socket. You need to removed TSocketServer from the project, replace it with TWSocket and sanity should prevail. Angus -- 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
Re: [twsocket] Force UDP source port when sending
Hello Angus, I have a SocketServer because it's the way to make a listening UDP server isn't it ? It listen for incoming UDP on port 1812, I subclassed it to add some more properties. When OnDataAvailable I try to send UDP data back to sender but with same 1812 src port and this produce the bind error. regards. >> TMySocketServer ARMSL> Why are you using this component, UDP needs only TWSocket, or have you ARMSL> subclassed TWSocket for some reason? ARMSL> But this stuff works in numerous other applications, there must be ARMSL> something else in error in your application that is causing bind to fail. ARMSL> Angus -- 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
Re: [twsocket] Force UDP source port when sending
> TMySocketServer Why are you using this component, UDP needs only TWSocket, or have you subclassed TWSocket for some reason? But this stuff works in numerous other applications, there must be something else in error in your application that is causing bind to fail. Angus -- 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
Re: [twsocket] Force UDP source port when sending
Hello Angus, I still get Bind error using this (simplified) code :-( procedure TFormMain.WSocketListenerDataAvailable(Sender: TObject; ErrCode: Word); begin TMySocketServer(sender).ReceiveFrom(@BufRadiusAnswerDataAvailable,512,SrcSocket,SrcSocketLen); try TMySocketServer(sender).SendTo(SrcSocket,SrcSocketLen,@BufRadiusAnswerDataAvailable,512); except on E: Exception do begin DisplayLog('Exception : '+E.Message); end; end; 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
Re: [twsocket] Force UDP source port when sending
You don't 'connect' UDP, it's already listening. And use SendTo, not Send. Angus Original Message -------- *Subject:* Re: [twsocket] Force UDP source port when sending *From:* Dod <[EMAIL PROTECTED]> *To:* ICS support mailing *Date:* Sat, 28 Jun 2008 19:27:44 +0200 Hello Angus, Settings the property do not produce the error, it's on .Connect/.Send that exception raise. Regards. ARMSL> You don't need to send your reply from the event, just make Src a public ARMSL> variable associated with this specific socket, and use SendTo later. I ARMSL> think your issue is trying to set a property, rather than actually ARMSL> sending a packet. ARMSL> Angus ARMSL> -------- Original Message ---- ARMSL> *Subject:* Re: [twsocket] Force UDP source port when sending ARMSL> *From:* Dod <[EMAIL PROTECTED]> ARMSL> *To:* ICS support mailing ARMSL> *Date:* Sat, 28 Jun 2008 18:06:32 +0200 ARMSL> Hello Angus, ARMSL> Thank you, so I cannot force the port to same as listening but if I do ARMSL> it within the OnDataAvailable then the .SendTo will automatically ARMSL> re-use the same socket to send data back using same src port whenever ARMSL> this port is actually used for listening by the server ? ARMSL> So this also mean that the OnDataAvailable procedure may take a while ARMSL> to get outside if I need to do lenghtly operation. Is there a way to ARMSL> "keep" this socket to re-use later ? ARMSL> 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 ARMSL> 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; ARMSL> 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> = ARMSL>> SOCKET_ERROR then ARMSL> TriggerQueryDone(FWUDPSocket.LastError); ARMSL>> end; ARMSL> -- ARMSL> To unsubscribe or change your settings for TWSocket mailing list ARMSL> please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket ARMSL> 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 -- 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
Re: [twsocket] Force UDP source port when sending
Hello Angus, Settings the property do not produce the error, it's on .Connect/.Send that exception raise. Regards. ARMSL> You don't need to send your reply from the event, just make Src a public ARMSL> variable associated with this specific socket, and use SendTo later. I ARMSL> think your issue is trying to set a property, rather than actually ARMSL> sending a packet. ARMSL> Angus ARMSL> Original Message -------- ARMSL> *Subject:* Re: [twsocket] Force UDP source port when sending ARMSL> *From:* Dod <[EMAIL PROTECTED]> ARMSL> *To:* ICS support mailing ARMSL> *Date:* Sat, 28 Jun 2008 18:06:32 +0200 ARMSL> Hello Angus, ARMSL> Thank you, so I cannot force the port to same as listening but if I do ARMSL> it within the OnDataAvailable then the .SendTo will automatically ARMSL> re-use the same socket to send data back using same src port whenever ARMSL> this port is actually used for listening by the server ? ARMSL> So this also mean that the OnDataAvailable procedure may take a while ARMSL> to get outside if I need to do lenghtly operation. Is there a way to ARMSL> "keep" this socket to re-use later ? ARMSL> 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 ARMSL> 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; ARMSL> 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> = ARMSL>> SOCKET_ERROR then ARMSL> TriggerQueryDone(FWUDPSocket.LastError); ARMSL>> end; ARMSL> -- ARMSL> To unsubscribe or change your settings for TWSocket mailing list ARMSL> please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket ARMSL> 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
Re: [twsocket] Force UDP source port when sending
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 *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
Re: [twsocket] Force UDP source port when sending
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
Re: [twsocket] Force UDP source port when sending
> 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 ? Yes, this is the (simplified) code from the ICS SNTP Time Server that responds to a UDP request with the time to the same IP and port. http://www.magsys.co.uk/download/software/sntp.zip Angus procedure TTimeServ.WUDPSocketDataAvailable(Sender: TObject; Error: Word); var Buffer : array [0..1023] of char; Src: TSockAddrIn; SrcLen : Integer; NewTime : LongWord; DataPtr : TWSocketData ; begin SrcLen := SizeOf(Src); FWUDPSocket.ReceiveFrom(@Buffer, SizeOf(Buffer), Src, SrcLen); SrcIPAddr := Src ; NewTime := Trunc ((GetUTCTime - 2) * 24 * 60 * 60) ; ByteSwaps (@NewTime, SizeOf(NewTime)) ; DataPtr := @NewTime ; if FWUDPSocket.Sendto (Src, SrcLen, DataPtr, SizeOf(NewTime)) = SOCKET_ERROR then TriggerQueryDone(FWUDPSocket.LastError); 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