[Gambas-user] Binding UdpSocket to specific IP
gen braga
genbraga1 at gmail.com
Thu Jan 10 17:19:21 CET 2019
Hello Hans
Not exactly.
For example, my NIC has 2 IP addresses, 10.0.0.50/8 and 192.168.0.
<http://192.168.0.50/24>50/24
When I Bind the udp socket to port 4500, i have both 10.0.0.50:4500 and
192.168.0.50:4500 avaiable.
What If i need only 10.0.0.50:4500?
I could use 192.168.0.50:4500 to something else.
I hope I have managed to clarify.
Thanks in advance!
Em qui, 10 de jan de 2019 11:32, Hans Lehmann <hans at gambas-buch.de escreveu:
> Hello,
>
> can this section of code help?
>
> CODE:
>
> ' Gambas class file
>
> Public UDPClient As UdpSocket
>
> Public Sub Form_Open()
> UDPClient = New UdpSocket As "UDPClient"
>
> UDPClient.Port = 0
> UDPClient.Bind()
> *UDPClient.Targetport = 123 *
> * UDPClient.TargetHost = "192.53.103.108" ' German time server:
> ptbtime1.ptb.de <http://ptbtime1.ptb.de>*
>
> Write #UDPClient, Chr$(35) & String$(47, Chr$(0)), 48
>
> End
> Public Sub UDPClient_Read()
> Dim sData As String
> Dim i As Integer
> Dim VSeconds As Long
> Dim CurrentDate As Date
> Dim iVSeconds As Integer
>
> Read #UDPClient, sData, Lof(UDPClient)
>
> For i = 17 To 20
> VSeconds += Asc(Mid$(sData, 37 - i, 1)) * 256 ^ (i - 17)
> Next
> iVSeconds = VSeconds - 2208988800 - System.TimeZone
> CurrentDate = DateAdd("01/01/1970", gb.second, iVSeconds)
> Print "Received Time: "; CurrentDate
>
> End
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20190110/f65ecab6/attachment-0001.html>
More information about the User
mailing list