2017-04-05 08:19:59 +00:00
|
|
|
/*
|
|
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
|
|
* To change this template file, choose Tools | Templates
|
|
|
|
* and open the template in the editor.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package commandterminal;
|
|
|
|
|
2017-04-13 17:57:30 +00:00
|
|
|
import java.io.IOException;
|
2017-04-05 08:19:59 +00:00
|
|
|
import java.net.DatagramPacket;
|
|
|
|
import java.net.DatagramSocket;
|
|
|
|
import java.net.InetAddress;
|
|
|
|
import java.net.SocketException;
|
2017-04-13 17:57:30 +00:00
|
|
|
import java.net.UnknownHostException;
|
2017-04-05 08:19:59 +00:00
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author lmascaro
|
|
|
|
*/
|
|
|
|
public class CommandTerminal {
|
|
|
|
|
2017-04-13 17:57:30 +00:00
|
|
|
private final static int SGCA_MULTICAST_PORT = 4446;
|
|
|
|
private final static String SCGA_MULTICAST_ADDRESS = "224.0.0.3";
|
2017-04-05 08:19:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param args the command line arguments
|
|
|
|
*/
|
|
|
|
public static void main(String[] args){
|
|
|
|
|
2017-04-13 17:57:30 +00:00
|
|
|
/*
|
|
|
|
* Handshake
|
|
|
|
*/
|
|
|
|
|
|
|
|
try {
|
|
|
|
DatagramSocket socket = new DatagramSocket();
|
|
|
|
ByteBuffer buf = ByteBuffer.allocate(19);
|
|
|
|
buf.clear();
|
|
|
|
buf.put((byte)(0x01|0x02));
|
|
|
|
|
|
|
|
DatagramPacket payload = new DatagramPacket(buf.array(),buf.array().length,InetAddress.getByName(SCGA_MULTICAST_ADDRESS),SGCA_MULTICAST_PORT);
|
|
|
|
socket.send(payload);
|
|
|
|
|
|
|
|
socket.receive(payload);
|
|
|
|
|
|
|
|
buf = ByteBuffer.wrap(payload.getData());
|
|
|
|
|
|
|
|
if(buf.get() == 3){
|
|
|
|
System.out.println("--Connection request successful");
|
|
|
|
byte address[] = new byte[9];
|
|
|
|
buf = buf.get(address,0,9);
|
|
|
|
String addressString = new String(address);
|
|
|
|
InetAddress sgcaAddress = InetAddress.getByName(addressString);
|
|
|
|
buf = buf.get(address,0,7);
|
|
|
|
short shortVal = buf.getShort();
|
|
|
|
int port = shortVal >= 0 ? shortVal : 0x10000 + shortVal;
|
|
|
|
System.out.println("----Address : "+sgcaAddress.getHostAddress());
|
|
|
|
System.out.println("----Port : "+port);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch ( IOException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-05 08:19:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|