Package programming5.code

Examples of programming5.code.RandomIndexGenerator


        super(myServer);
        try {
            accepter = new ServerSocket(0);
        }
  catch (IOException ioe) {
            throw new NetworkException("TCPServerAcceptThread: Couldn't create server socket: " + ioe.getMessage());
        }
    }
View Full Code Here


                port = 0;
            }
            accepter = new ServerSocket(port);
        }
  catch (IOException ioe) {
            throw new NetworkException("TCPServerAcceptThread: Couldn't create server socket: " + ioe.getMessage());
        }
    }
View Full Code Here

     *arrives from any of the open connections.
     *@return the packet of bytes
     */
    public byte[] receiveBytes() {
        byte[] ret = null;
        ReceiveRequest myRequest = new ReceiveRequest();
        synchronized (receiveRequests) {
            receiveRequests.add(myRequest);
        }
        myRequest.awaitUninterruptibly();
        if (myRequest.isDone()) {
            ret = myRequest.getMessage();
        }
        return ret;
    }
View Full Code Here

     *arrives from any of the open connections or timeout occurs.
     *@return the packetof bytes
     */
    public byte[] receiveBytes(long timeout) throws InterruptedException {
        byte[] ret = null;
        ReceiveRequest myRequest = new ReceiveRequest();
        synchronized (receiveRequests) {
            receiveRequests.add(myRequest);
        }
        myRequest.await(timeout, TimeUnit.MILLISECONDS);
        if (myRequest.isDone()) {
            ret = myRequest.getMessage();
        }
        return ret;
    }
View Full Code Here

     *@return the message bytes
     */
    @Override
    public byte[] receiveBytes() {
        byte[] ret = null;
        ReceiveRequest myRequest = new ReceiveRequest();
        synchronized (receiveRequests) {
            receiveRequests.add(myRequest);
        }
        myRequest.awaitUninterruptibly();
        if (myRequest.isDone()) {
            ret = myRequest.getMessage();
        }
        return ret;
    }
View Full Code Here

     *@return the message bytes
     */
    @Override
    public byte[] receiveBytes(long timeout) throws InterruptedException {
        byte[] ret = null;
        ReceiveRequest myRequest = new ReceiveRequest();
        synchronized (receiveRequests) {
            receiveRequests.add(myRequest);
        }
        myRequest.await(timeout, TimeUnit.MILLISECONDS);
        if (myRequest.isDone()) {
            ret = myRequest.getMessage();
        }
        return ret;
    }
View Full Code Here

     *@return the message bytes
     */
    @Override
    public byte[] receiveBytes() {
        byte[] ret = null;
        ReceiveRequest myRequest = new ReceiveRequest();
        synchronized (receiveRequests) {
            receiveRequests.add(myRequest);
        }
        myRequest.awaitUninterruptibly();
        if (myRequest.isDone()) {
            ret = myRequest.getMessage();
        }
        return ret;
    }
View Full Code Here

     *@return the message bytes
     */
    @Override
    public byte[] receiveBytes(long timeout) throws InterruptedException {
        byte[] ret = null;
        ReceiveRequest myRequest = new ReceiveRequest();
        synchronized (receiveRequests) {
            receiveRequests.add(myRequest);
        }
        myRequest.await(timeout, TimeUnit.MILLISECONDS);
        if (myRequest.isDone()) {
            ret = myRequest.getMessage();
        }
        return ret;
    }
View Full Code Here

        while (!done) {
            try {
                message = client.receive(timeout);
                if (message != null) {
                    try {
                        receivedMsg = new ReliableProtocolMessage(message.getBytes());
                        if (receivedMsg.isAcknowledge() && receivedMsg.getSequence() == enforcedMsg.getSequence()) {
                            done = true;
                        }
                    }
                    catch (MalformedMessageException mme) {
View Full Code Here

     */
    @Override
    public void signalEvent(MessageArrivedEvent protocolEvent) {
        if (protocolEvent != null) {
            try {
                ReliableProtocolMessage rcvdMsg = new ReliableProtocolMessage(protocolEvent.getContentBytes());
                if (rcvdMsg.isAcknowledge()) {
                    Debug.println("RUDP Ack received for " + rcvdMsg.getSequence() + " at " + rcvdMsg.getIndex(), "programming5.net.sockets.ReliableUDPClient");
                    synchronized (messageTable) {
                        ReliableProtocolMessage[] sentSequence = messageTable.get(rcvdMsg.getSequence());
                        if (sentSequence != null) {
                            sentSequence[rcvdMsg.getIndex()-1].signalAcked();
                        }
                    }
                }
                else {
                    long sequence = rcvdMsg.getSequence();
                    ReliableProtocolMessage ack = new ReliableProtocolMessage(sequence, rcvdMsg.getIndex());
                    try {
                        client.replyTo(protocolEvent, ack.getMessageBytes());
                    }
                    catch (NetworkException ne) {
                        Debug.printStackTrace(ne);
                    }
                    String streamID = ((AsynchMessageArrivedEvent) protocolEvent).getSourceURL() + "/" + Long.toString(rcvdMsg.getSequence());
View Full Code Here

TOP

Related Classes of programming5.code.RandomIndexGenerator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.