-
-
Save HudsonAfonso/8c0c70e85925932a583f7aad2325badb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import javax.xml.bind.DatatypeConverter; | |
import java.io.IOException; | |
import java.net.DatagramPacket; | |
import java.net.InetAddress; | |
import java.net.MulticastSocket; | |
import java.net.NetworkInterface; | |
public class Companytec { | |
public static void main(String[] args) throws IOException { | |
//Address | |
String multiCastAddress = "255.255.255.255"; | |
final int multiCastPort = 30718; | |
final int bufferSize = 1024 * 4; | |
//Create Socket | |
InetAddress group = InetAddress.getByName(multiCastAddress); | |
MulticastSocket s = new MulticastSocket(28675); | |
s.setNetworkInterface(NetworkInterface.getByName("en0")); | |
// s.joinGroup(group); | |
byte[] data = DatatypeConverter.parseBase64Binary("AAEA9g=="); | |
//Send data | |
s.send(new DatagramPacket(data, data.length, group, multiCastPort)); | |
// while (true) { | |
//Create buffer | |
byte[] buffer = new byte[bufferSize]; | |
DatagramPacket dgram = new DatagramPacket(buffer, bufferSize, group, multiCastPort); | |
s.receive(dgram); | |
String inetaddress = (dgram.getAddress()).getHostAddress(); | |
String msg = new String(buffer); | |
// System.out.println(msg); | |
// System.out.println(inetaddress); | |
if (msg.indexOf("X90") > 0) { | |
System.out.println(inetaddress); | |
// break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment