Skip to content
Snippets Groups Projects
Commit 5d54379e authored by J. M. Bailey's avatar J. M. Bailey
Browse files

Improve API a bit

parent 67ef3d6f
No related branches found
No related tags found
No related merge requests found
...@@ -49,20 +49,23 @@ public class DisThreadedNetIF ...@@ -49,20 +49,23 @@ public class DisThreadedNetIF
} }
/* *********** class instanciation ************* */ /* *********** class instanciation ************* */
private int DIS_PORT = 3000; public static int DEFAULT_DIS_PORT = 3000;
private String MCAST_GROUP = "225.4.5.6"; public static String DEFAULT_MCAST_GROUP = "225.4.5.6";
private static final int MAX_DIS_PDU_SIZE = 8192; private static final int MAX_DIS_PDU_SIZE = 8192;
private int disPort;
private String mcastGroup;
private boolean killed = false; private boolean killed = false;
private DisThreadedNetIF() private DisThreadedNetIF()
{ {
this(3000, "225.4.5.6"); this(DEFAULT_DIS_PORT, DEFAULT_MCAST_GROUP);
} }
private DisThreadedNetIF(int port, String mcastgroup) private DisThreadedNetIF(int port, String mcastgroup)
{ {
DIS_PORT = port; disPort = port;
MCAST_GROUP = mcastgroup; mcastGroup = mcastgroup;
init(); init();
} }
...@@ -101,6 +104,16 @@ public class DisThreadedNetIF ...@@ -101,6 +104,16 @@ public class DisThreadedNetIF
}); });
} }
public int getDisPort()
{
return disPort;
}
public String getMcastGroup()
{
return mcastGroup;
}
public void send(Pdu pdu) public void send(Pdu pdu)
{ {
pdus2send.add(pdu); pdus2send.add(pdu);
...@@ -131,8 +144,8 @@ public class DisThreadedNetIF ...@@ -131,8 +144,8 @@ public class DisThreadedNetIF
DatagramPacket packet; DatagramPacket packet;
while (!killed) { // keep trying on error while (!killed) { // keep trying on error
try { try {
socket = new MulticastSocket(DIS_PORT); socket = new MulticastSocket(disPort);
InetAddress maddr = InetAddress.getByName(MCAST_GROUP); InetAddress maddr = InetAddress.getByName(mcastGroup);
socket.setNetworkInterface(findIp4Interface()); socket.setNetworkInterface(findIp4Interface());
socket.joinGroup(maddr); socket.joinGroup(maddr);
while (!killed) { while (!killed) {
...@@ -162,7 +175,7 @@ public class DisThreadedNetIF ...@@ -162,7 +175,7 @@ public class DisThreadedNetIF
private final Runnable sendThread = () -> { private final Runnable sendThread = () -> {
while (!killed) { while (!killed) {
try { try {
InetAddress maddr = InetAddress.getByName(MCAST_GROUP); InetAddress maddr = InetAddress.getByName(mcastGroup);
while (!killed) { while (!killed) {
Pdu pdu = pdus2send.take(); Pdu pdu = pdus2send.take();
...@@ -173,7 +186,7 @@ public class DisThreadedNetIF ...@@ -173,7 +186,7 @@ public class DisThreadedNetIF
pdu.marshal(dos); pdu.marshal(dos);
byte[] data = baos.toByteArray(); byte[] data = baos.toByteArray();
// load byte buffer into packet and send // load byte buffer into packet and send
DatagramPacket packet = new DatagramPacket(data, data.length, maddr, DIS_PORT); DatagramPacket packet = new DatagramPacket(data, data.length, maddr, disPort);
socket.send(packet); socket.send(packet);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment