Re: [twsocket] Force UDP source port when sending

2008-07-02 Thread Dod
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

2008-07-02 Thread Angus Robertson - Magenta Systems Ltd
 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

2008-07-02 Thread Angus Robertson - Magenta Systems Ltd
 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

2008-07-02 Thread Dod
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

2008-07-02 Thread Hoby Smith
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

2008-07-02 Thread Dod
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

2008-07-02 Thread Dod
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

2008-07-02 Thread Angus Robertson - Magenta Systems Ltd
 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

2008-07-02 Thread Dod
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

2008-07-02 Thread Dod
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

2008-07-01 Thread Dod
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

2008-07-01 Thread Angus Robertson - Magenta Systems Ltd
 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

2008-06-28 Thread Dod
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

2008-06-28 Thread Angus Robertson - Magenta Systems Ltd
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


[twsocket] Force UDP source port when sending

2008-06-25 Thread Dod
Hello,

I  have  an  application (EXE file without sources) that listen UDP on
port  1812  and  when  it  receive data, it send an UDP paquet back to
sender with same source 1812 port.

I  have to do same application but I get exception already binded if
I   use  MySocket.LocalPort:=1812  to  send  paquet  back,  if  I  use
MySocket.LocalPort:=0  it  works  but  on  the  other application will
simply ignore the paquet as src is not 1812 (this is the way it works,
I cannot change this).

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 ?

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

2008-06-25 Thread Angus Robertson - Magenta Systems Ltd
 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