-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
284 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #include "mbed.h" | ||
| #include "EthernetInterface.h" | ||
|
|
||
| const int BROADCAST_PORT = 58083; | ||
|
|
||
| int main() { | ||
| EthernetInterface eth; | ||
| eth.init(); //Use DHCP | ||
| eth.connect(); | ||
|
|
||
| UDPSocket socket; | ||
| socket.bind(BROADCAST_PORT); | ||
| socket.set_broadcasting(); | ||
|
|
||
| Endpoint broadcaster; | ||
| char buffer[256]; | ||
| while (true) { | ||
| printf("\nWait for packet...\n"); | ||
| int n = socket.receiveFrom(broadcaster, buffer, sizeof(buffer)); | ||
| buffer[n] = '\0'; | ||
| printf("Packet from \"%s\": %s\n", broadcaster.get_address(), buffer); | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #include "mbed.h" | ||
| #include "EthernetInterface.h" | ||
|
|
||
| const int BROADCAST_PORT = 58083; | ||
|
|
||
| int main() { | ||
| EthernetInterface eth; | ||
| eth.init(); //Use DHCP | ||
| eth.connect(); | ||
|
|
||
| UDPSocket sock; | ||
| sock.init(); | ||
| sock.set_broadcasting(); | ||
|
|
||
| Endpoint broadcast; | ||
| broadcast.set_address("255.255.255.255", BROADCAST_PORT); | ||
|
|
||
| char out_buffer[] = "very important data"; | ||
|
|
||
| while (true) { | ||
| printf("Broadcasting...\n"); | ||
| sock.sendTo(broadcast, out_buffer, sizeof(out_buffer)); | ||
| Thread::wait(1000); | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #include "mbed.h" | ||
| #include "EthernetInterface.h" | ||
|
|
||
| const char* MCAST_GRP = "224.1.1.1"; | ||
| const int MCAST_PORT = 5007; | ||
|
|
||
| int main() { | ||
| EthernetInterface eth; | ||
| eth.init(); //Use DHCP | ||
| eth.connect(); | ||
|
|
||
| UDPSocket server; | ||
| server.bind(MCAST_PORT); | ||
| if (server.join_multicast_group(MCAST_GRP) != 0) { | ||
| printf("Error joining the multicast group\n"); | ||
| while (true) {} | ||
| } | ||
|
|
||
| Endpoint client; | ||
| char buffer[256]; | ||
| while (true) { | ||
| printf("\nWait for packet...\n"); | ||
| int n = server.receiveFrom(client, buffer, sizeof(buffer)); | ||
|
|
||
| printf("Packet from \"%s\": %s\n", client.get_address(), buffer); | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #include "mbed.h" | ||
| #include "EthernetInterface.h" | ||
|
|
||
| const char* MCAST_GRP = "224.1.1.1"; | ||
| const int MCAST_PORT = 5007; | ||
|
|
||
| int main() { | ||
| EthernetInterface eth; | ||
| eth.init(); //Use DHCP | ||
| eth.connect(); | ||
|
|
||
| UDPSocket sock; | ||
| sock.init(); | ||
|
|
||
| Endpoint multicast_group; | ||
| multicast_group.set_address(MCAST_GRP, MCAST_PORT); | ||
|
|
||
| char out_buffer[] = "very important data"; | ||
| while (true) { | ||
| printf("Multicast to group: %s\n", MCAST_GRP); | ||
| sock.sendTo(multicast_group, out_buffer, sizeof(out_buffer)); | ||
| Thread::wait(1000); | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import socket | ||
|
|
||
| BROADCAST_PORT = 58083 | ||
|
|
||
| s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | ||
| s.bind(('0.0.0.0', BROADCAST_PORT)) | ||
|
|
||
| while True: | ||
| print s.recvfrom(256) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import socket | ||
| from time import sleep, time | ||
|
|
||
| BROADCAST_PORT = 58083 | ||
|
|
||
| s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | ||
| s.bind(('', 0)) | ||
| s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) | ||
|
|
||
| while True: | ||
| print "Broadcasting..." | ||
| data = 'Hello World: ' + repr(time()) + '\n' | ||
| s.sendto(data, ('<broadcast>', BROADCAST_PORT)) | ||
| sleep(1) |
Oops, something went wrong.