/* * MulticastSendingThreaed.java */ package boondock.holdem.Server; import java.io.*; import java.net.*; import boondock.holdem.Network.*; /** * Class for delivering outgoing messages via datagrams packets * * @author Jonathan O'Keefe * @author Scott Semonian * @author Matt Brinza * @author Hamid R. Tahsildoost * * @author The Boondock Saints * @author No Limit Texas Holdem */ public class MulticastSendingThread extends Thread { private byte[] messageBytes; /** * Constructor which invokes super class and stores bytes * * @param bytes Bytes to be sent across the thread. */ public MulticastSendingThread(byte[] bytes){ super("MulticastSendingThread"); messageBytes = bytes; } /** * Deliver message to MUTLICAST_ADDRESS, which is in the constants class, over DatagramSocket */ public synchronized void run(){ try { DatagramSocket socket = new DatagramSocket(constants.MULTICAST_SENDING_PORT); InetAddress group = InetAddress.getByName(constants.MULTICAST_ADDRESS); DatagramPacket packet = new DatagramPacket(messageBytes, messageBytes.length, group,constants.MULTICAST_LISTENING_PORT); socket.send(packet); socket.close(); } catch (IOException ioException) { try { wait(500); } catch(Exception e) { } // String errorMessage = "ERROR_MESSAGE" + constants.MESSAGE_SEPARATOR + "Unable to bind address. You may need to retry your last action."; // new MulticastSendingThread(errorMessage.getBytes()).start(); //ioException.printStackTrace(); } } }//end of MulticastSendingThread class