Hello Skok,

Add one TWSocket for sending data and one TWSocketServer for

In TWSocket do the .Send or .SendStr to and do .Close
in OnDataSent.

Do .Listen for your TWSocketServer and check OnDataAvailable.

That's  all,  I  have  done  a tool that do same thing you want, "auto
detect clients" tool that send a broadcast and show each machine with
"client.exe" that answer to my broadcast.


ST> Well, I'm trying to do server and client UDP with one component. So, if 
ST> I want do receive udp packet from network, I have to do Listen on some 
ST> port, and if I want to send UDP packets, I hava to do Send. But since 
ST> component is already listening, I can send only with SendTo. And this 
ST> sendto must be broadcast.
ST> I'm tyring to combine udplistener and udpsender demos into one component.
ST> Timer is used to notify other machines (same application) in intervals 
ST> thar sender is still alive. I'm not trying to do server-client 
ST> communication. I'm trying to do standalone application that would know 
ST> abount others (same application) over udp.

ST> Dod wrote:
>> Hello Skok,
>> I don't really know what the problem is but I think you do something
>> too complicated...
>> A simple .Send to is enought, then OnDataSent do a .Close
>> why use a TTimer ?
>> ST> I'm trying to create application that would run on multiple machines. 
>> ST> This application has to know IP addresses of all other machines running 
>> ST> same software.
>> ST> I'm trying to do something like discovery on network. Protocol I decided 
>> ST> to use for discovery is UDP. On mailing list I already saw, that only 
>> ST> one TWSocket component
>> ST> can be used for receiving and sending data. So, I wrote following code 
>> ST> for listening:
>> ST> UDPSocket.Proto :='udp';
>> ST> UDPSocket.Addr :='';
>> ST> UDPSocket.Port :='1234';
>> ST> UDPSocket.Listen;
>> ST> Timer1.Enabled :=True;
>> ST> and on timer event there is code for sending broadcast data to notofy 
>> ST> others about existence:
>> ST> procedure TForm1.Timer1Timer(Sender: TObject);
>> ST> var
>> ST>   SendTo:TSockAddrIn;
>> ST>   LenSendTo:integer;
>> ST>   Data:string;
>> ST> begin
>> ST>   LenSendTo:=SizeOf(SendTo);
>> ST>   Data:='Test'+#0;
>> ST>   SendTo.sin_port :=htons(1234);
>> ST>   SendTo.sin_addr :=StrToInAddr('');
>> ST>   SendTo.sin_family :=AF_INET;
>> ST>   UDPSocket.SendTo(SendTo,LenSendTo,@Data[1],Length(Data));
>> ST> end;
>> ST> StrToInAddr is function that I found in mailing list.
>> ST> On receive even I have code from udplistener sample:
>> ST> var
>> ST>     Buffer : array [0..1023] of char;
>> ST>     Len    : Integer;
>> ST>     Src    : TSockAddrIn;
>> ST>     SrcLen : Integer;
>> ST> begin
>> ST>     SrcLen := SizeOf(Src);
>> ST>     Len    := WSocket.ReceiveFrom(@Buffer, SizeOf(Buffer), Src, SrcLen);
>> ST>     if Len >= 0 then begin
>> ST>           Buffer[Len] := #0;
>> ST>           listbox1.Items.Add(StrPas(Buffer));
>> ST>     end;
>> ST> end;
>> ST> Problem is that sending is ok (no error), but ondataavaliable event 
>> ST> never gets fired, so I'm assuming that nothing is sent.
>> ST> What am I doing wrong.
>> ST> P.S. I have been using ICS for awhile now and I think that this is most 
>> ST> stable component suite for networking. Keep the good work.
>> ST> Regards,
>> ST> Skok Tone

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