Hello Hugo,
thank you for your reply: If I got you right, an open UPD Socket is always a server socket by default, that accepts requests from any IP source address, as long as the PORT is matching? And I always have to filter the incoming datagrams with GetRemoteSinIP to establish a point-to-pont connection? Mit freundlichem Gruß / Yours sincerely / Cordialement Christian Sporer logo_ohne_untertitel_1 Grüntenstr.18 80686 München Tel.: +(49) 89 54217952 Fax.: +(49) 89 52389119 Von: Domibay - Hugo [mailto:h...@domibay.org] Gesendet: Freitag, 22. Oktober 2021 14:23 An: synalist-public@lists.sourceforge.net Betreff: Re: [Synalist] understanding UDP sockets Hello, On an UDP data flow the receiving end uses the "Bind()" method and the sending end uses the "Connect()" method. The life time of a socket starts with the "TUDPBlockSocket.CreateSocket()" call and ends with the "TUDPBlockSocket.CloseSocket()" call. During the life time of the socket the sending part can use different "Connect()" calls to send messages to different targets. But on the receiving end the "Bind()" method can be used only once. In this use case "UDP_trx.udpsock" is the receiving end. The sending end you find with "GetRemoteSinIP()" and "GetRemoteSinPort()" method calls that will turn you a different port than that "UDP_trx.udpsock" has bound to. That is where the potential response would go to. The receiving end must listen for data with the "RecvPacket()" call while the "WaitingData()" call will tell whether data arrived while the the receiving end was not listening. Certainly it will be "0" at the beginning because the socket did not exist yet. Received data can only stack up when the socket on the receiving end was already bound successfully. I hope that helps a bit. Best Regards, Hugo El 22/10/21 a las 11:05, S.C.T.N GmbH escribió: Hello I need help to understand the basic concept of UDP sockets: I am trying to set up a point-to-point connection between host A(192.168.2.222:4000) and host B(192.168.2.224:4000) I am opening the socket like this: ------------------------------------------------------------------ function UDP_trx.s_open(IP,PORT:string):boolean; begin udpsock:=TUDPBlockSocket.Create; udpsock.Bind('0.0.0.0',PORT); // bind socket to local NIC ? udpsock.Connect(IP,PORT); // connect socket to remote IP:PORT ? end; ----------------------------------------------------------------- I am sending one byte over the socket (do I need to connect for every SendByte?) ----------------------------------------------------------------- procedure UDP_trx.s_tx(txbyte:byte; IP,PORT:string); var i:integer; s:string; begin //udpsock.Connect(IP,PORT); // do I need to reconnect every time? udpsock.SendByte(txbyte); end; ----------------------------------------------------------------- And I am receiving one byte over the socket like this: ----------------------------------------------------------------- function UDP_trx.s_rx(var rxbyte:byte; IP,UDPPRT:string):boolean; var ipstr:string; prt:integer; begin if udpsock.WaitingDataEx=0 then begin result:=false; exit; end; rxbyte:=udpsock.RecvByte(1); //ipstr:=udpsock.GetRemoteSinIP; //prt:=udpsock.GetRemoteSinPort; //if (ipstr=IP) and (prt=StrToInt(UDPPRT)) then begin result:=true; exit; end; //filter for RemoteSin result:=true; end; ----------------------------------------------------------------- What I do not understand is this: Whenever I send a byte to any IP adress (even one that does not exist) I am receiving a byte at the remote end as long as the port is matching. Only when I use the s_rx filter with GetRemoteSinIP and GetRemoteSinPort I can be sure that I receive from the correct source IP. So I suppose that I have not really understood how to use BIND and CONNECT Thank you for help Mit freundlichem Gruß / Yours sincerely / Cordialement Christian Sporer Grüntenstr.18 80686 München Tel.: +(49) 89 54217952 Fax.: +(49) 89 52389119 _______________________________________________ synalist-public mailing list synalist-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/synalist-public
_______________________________________________ synalist-public mailing list synalist-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/synalist-public