Package de.fhkn.in.uce.stun.message

Examples of de.fhkn.in.uce.stun.message.MessageReader


        requestConnectionMessage.addAttribute(new RelayingAttribute());
        requestConnectionMessage.writeTo(controlConnection.getOutputStream());
    }

    private Message receiveConnectionResponse(final Socket controlConnection) throws IOException {
        final MessageReader messageReader = MessageReader.createMessageReader();
        return messageReader.readSTUNMessage(controlConnection.getInputStream());
    }
View Full Code Here


        try {
            while (!this.isInterrupted()) {
                logger.info("listen on {}:{}", this.controlConnection.getLocalPort(), this.controlConnection //$NON-NLS-1$
                        .getLocalAddress().getHostAddress());
                while (!this.isInterrupted()) {
                    final MessageReader messageReader = MessageReader.createMessageReader();
                    final Message requestMessage = messageReader.readSTUNMessage(this.controlConnection
                            .getInputStream());
                    if (requestMessage.isMethod(STUNMessageMethod.CONNECTION_REQUEST)) {
                        this.handleConnectionRequestMessage(requestMessage);
                    } else if (requestMessage.isMethod(STUNMessageMethod.KEEP_ALIVE)) {
                        this.handleKeepAliveMessage(requestMessage);
View Full Code Here

     */
    public void run() {
        Message message;
        while (!cancelled) {
            try {
                final MessageReader messageReader = this.createCustomRelayingMessageReader();
                message = messageReader.readSTUNMessage(controlConnection.getInputStream());
                if (message == null) {
                    // server closed connection
                    logger.error("IOException while receiving message (message was null)");
                    socketQueue.add(new Socket());
                    return;
View Full Code Here

     * request error is returned to the client.
     */
    public void run() {
        Message message;
        try {
            final MessageReader messageReader = this.createCustomRelayingMessageReader();
            logger.debug("Reading incoming message from {}", s.toString()); //$NON-NLS-1$
            message = messageReader.readSTUNMessage(s.getInputStream());
        } catch (IOException e) {
            logger.error("IOEXception while receiving message: {}", e.getMessage());
            return;
        }
        if (message.isMethod(RelayingMethod.ALLOCATION) && message.isRequest()) {
View Full Code Here

        requestConnectionMessage.writeTo(controlConnection.getOutputStream());
    }

    private InetSocketAddress processConnectionRequestResponse(final Socket controlConnection) throws Exception {
        InetSocketAddress result;
        final MessageReader messageReader = MessageReader.createMessageReader();
        final Message responseMessage = messageReader.readSTUNMessage(controlConnection.getInputStream());
        if (responseMessage.hasAttribute(XorMappedAddress.class)) {
            final XorMappedAddress xorMappedAddress = responseMessage.getAttribute(XorMappedAddress.class);
            result = xorMappedAddress.getEndpoint();
        } else {
            throw new Exception("The target endpoint is not returned by the mediator"); //$NON-NLS-1$
View Full Code Here

    private void handle() {
        int refreshInterval = initRefreshInterval;
        try {
            while (true) {
                controlConnection.setSoTimeout(refreshInterval * 1000);
                final MessageReader messageReader = this.createCustomRelayingMessageReader();
                final Message message = messageReader.readSTUNMessage(controlConnection.getInputStream());
                // check if it is refresh message (atm the only one that is
                // allowed)
                if (message == null) {
                    // connection closed
                    logger.error("Received message was null");
View Full Code Here

     */
    @SuppressWarnings("unused")
    private boolean waitForSuccessResponse(final STUNMessageMethod method, final Socket controlConnection)
            throws IOException {
        boolean result = false;
        final MessageReader messageReader = MessageReader.createMessageReader();
        final Message responseMessage = messageReader.readSTUNMessage(controlConnection.getInputStream());
        if (responseMessage.isMethod(method) && responseMessage.isSuccessResponse()) {
            result = true;
        }
        return result;
    }
View Full Code Here

        logger.debug("Sending allocation request to relay server"); //$NON-NLS-1$
        this.controlConnectionWriter.writeMessage(allocationRequest);
    }

    private synchronized Message receiveAllocationResponse() throws IOException {
        final MessageReader messageReader = this.createCustomRelayingMessageReader();
        final Message allocationResponse = messageReader.readSTUNMessage(this.controlConnection.getInputStream());
        if (!allocationResponse.isMethod(RelayingMethod.ALLOCATION) || !allocationResponse.isSuccessResponse()
                || !allocationResponse.hasAttribute(XorMappedAddress.class)
                || !allocationResponse.hasAttribute(RelayingLifetime.class)) {
            throw new IOException("Unexpected response from Relay server"); //$NON-NLS-1$
        }
View Full Code Here

        NATBehavior result = new NATBehavior();
        final Message requestMessage = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.REQUEST,
                STUNMessageMethod.NAT_REQUEST);
        requestMessage.addAttribute(new Username(targetId));
        requestMessage.writeTo(this.mediatorConnection.getControlConnection().getOutputStream());
        final MessageReader messageReader = MessageReader
                .createMessageReaderWithCustomAttributeTypeDecoder(new NATAttributeTypeDecoder());
        final Message response = messageReader.readSTUNMessage(this.mediatorConnection.getControlConnection()
                .getInputStream());
        if (response.hasAttribute(NATBehavior.class)) {
            result = response.getAttribute(NATBehavior.class);
        }
        this.logger.debug("target {} is behind nat {}", targetId, result.toString()); //$NON-NLS-1$
View Full Code Here

        final List<NATTraversalTechniqueAttribute> result = new ArrayList<NATTraversalTechniqueAttribute>();
        final Message requestMessage = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.REQUEST,
                STUNMessageMethod.SUPPORTED_TRAV_TECHS_REQUEST);
        requestMessage.addAttribute(new Username(targetId));
        requestMessage.writeTo(this.mediatorConnection.getControlConnection().getOutputStream());
        final MessageReader messageReader = MessageReader
                .createMessageReaderWithCustomAttributeTypeDecoder(new NATAttributeTypeDecoder());
        final Message response = messageReader.readSTUNMessage(this.mediatorConnection.getControlConnection()
                .getInputStream());
        if (response.hasAttribute(NATTraversalTechniqueAttribute.class)) {
            for (final NATTraversalTechniqueAttribute ntta : response
                    .getAttributes(NATTraversalTechniqueAttribute.class)) {
                result.add(ntta);
View Full Code Here

TOP

Related Classes of de.fhkn.in.uce.stun.message.MessageReader

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.