Skip to content

Instantly share code, notes, and snippets.

@asissuthar
Created November 28, 2017 15:32
Show Gist options
  • Save asissuthar/6eb3e27b0a571d0011f2842e7147a1bf to your computer and use it in GitHub Desktop.
Save asissuthar/6eb3e27b0a571d0011f2842e7147a1bf to your computer and use it in GitHub Desktop.
Receive Data Using Broadcast Class
package in.asissuthar;
import java.io.IOException;
import java.net.*;
public class Main {
public static void main(String[] args) {
try {
Broadcast broadcast = new Broadcast(8080);
broadcast.server();
DatagramPacket packet = broadcast.read(1024);
byte[] data = packet.getData();
System.out.println(new String(data));
broadcast.close();
} catch (SocketException socketException) {
socketException.printStackTrace();
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment