phpbb_admin Site Admin
Joined: 07 Feb 2007 Posts: 82
|
Posted: Sun Feb 11, 2007 20:24 UTC Post subject: Simple demonstration of using UDP to send broadcast packets |
|
|
Posted by brent.hildebrand on Wednesday, November 29, 2006 (EST)
Simple demonstration of using UDP to send broadcast packets. Using a UDP socket, you can send "broadcast" packets so that multiple computers can receive the packet of information in the broadcast. I've used this technique to autoconfigure several computers on a network. The broadcast packet allows the a program running on each computer to find each others IP address, and then use TCP to connect and sync data.
The main function is called "Broadcast". Enter the following to create a socket:
Broadcast ''
To send a broadcast packet, enter:
Broadcast 'Send' 'This is my broadcast text'
Broadcast uses
'SetSockOpt' 'sol_socket' 'so_broadcast' 1
'SetSockOpt' 'sol_socket' 'so_reuseaddr' 1
This allows the socket to be a broadcast socket, and the so_reuseaddr flag allows for testing on a single computer using multiple copies of APL running and reusing the same IP address for each instance. |
|