[Gambas-user] UDP Broadcast
Brian G
brian at westwoodsvcs.com
Thu Apr 29 18:43:45 CEST 2021
Hi this is an example that does what your looking for:
Sender example:
**************************************************
Public Sub Main()
Dim a As New UdpSocket As "MyBroadcast"
a.Broadcast = 1
a.port = 0
a.TargetHost = "192.168.1.255" ' <-- this needs to be your network segment machine addr of 255
a.TargetPort = "8002"
a.Bind()
if a.Status = Net.Active then
Write #a, "This is a test message"
Write #a, "More of This is a test message"
Flush #a
Close #a
endif
Catch
Print Error.text
End
********************************************
Receive side:
********************************************
Public Sub Main()
Dim a As New UdpSocket As "MyBroadcast"
a.broadcast = True
a.port = 8002
a.Bind()
While a.Status = Net.Active
Wait 0.01
Wend
Print "Hello world"
End
Public Sub MyBroadcast_read()
Dim buffer As String = ""
While Lof(Last)
buffer &= Read #Last, -254
Wend
Print buffer
End
Public Sub MyBroadcast_error()
Print Last.status
End
*****************************************
I hope this helps
"Failure is the key to success;
each mistake teaches us something" .. Morihei Ueshiba
Brian G
----- On Apr 28, 2021, at 12:21 PM, Brian brian at westwoodsvcs.com wrote:
> Are you able to do a wireshark capture to look at what is being sent?
>
> "Failure is the key to success;
> each mistake teaches us something" .. Morihei Ueshiba
> Brian G
>
> ----- Antonio Teixeira <antonio.j.teixeira at gmail.com> wrote:
>> Hi everyone,
>>
>> I have 4 machines in my network.
>> I am trying to do a small program to broadcast packets to the network so
>> each machine send a packet and all the other 3 receive the packet,
>> I tried based on the example but I can't reach the broadcast way.
>> Any help would be appreciated.
>>
>> Thank you in advance.
>>
>> Atentamente / Regards
>>
>> António Teixeira
>
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
More information about the User
mailing list