Search in sources :

Example 1 with AprSocketWrapperImpl

use of streamer.apr.AprSocketWrapperImpl in project cloudstack by apache.

the class ConsoleProxyRdpClient method initClient.

@Override
public void initClient(final ConsoleProxyClientParam param) {
    if ((System.currentTimeMillis() - _threadStopTime) < 1000) {
        return;
    }
    try {
        int canvasWidth = 1024;
        int canvasHeight = 768;
        setClientParam(param);
        final String host = param.getHypervHost();
        final String password = param.getPassword();
        final String instanceId = param.getClientHostAddress();
        final int port = param.getClientHostPort();
        final SSLState sslState = new SSLState();
        final String username = param.getUsername();
        String name = null;
        String domain = null;
        if (username.contains("\\")) {
            String[] tokens = username.split("\\\\");
            name = tokens[1];
            domain = tokens[0];
        } else {
            name = username;
            domain = "Workgroup";
        }
        _screen = new ScreenDescription();
        _canvas = new RdpBufferedImageCanvas(this, canvasWidth, canvasHeight);
        onFramebufferSizeChange(canvasWidth, canvasHeight);
        _screen.addSizeChangeListener(new SizeChangeListener() {

            @Override
            public void sizeChanged(int width, int height) {
                if (_canvas != null) {
                    _canvas.setCanvasSize(width, height);
                }
            }
        });
        s_logger.info("connecting to instance " + instanceId + " on host " + host);
        _client = new RdpClient("client", host, domain, name, password, instanceId, _screen, _canvas, sslState);
        _mouseEventSource = _client.getMouseEventSource();
        _keyEventSource = _client.getKeyEventSource();
        _worker = new Thread(new Runnable() {

            @Override
            public void run() {
                _socket = new AprSocketWrapperImpl("socket", sslState);
                Pipeline pipeline = new PipelineImpl("Client");
                pipeline.add(_socket, _client);
                pipeline.link("socket", _client.getId(), "socket");
                pipeline.validate();
                InetSocketAddress address = new InetSocketAddress(host, port);
                ConsoleProxy.ensureRoute(host);
                try {
                    _workerDone = false;
                    s_logger.info("Connecting socket to remote server and run main loop(s)");
                    _socket.connect(address);
                } catch (Exception e) {
                    s_logger.info(" error occurred in connecting to socket " + e.getMessage());
                } finally {
                    shutdown();
                }
                _threadStopTime = System.currentTimeMillis();
                s_logger.info("Receiver thread stopped.");
                _workerDone = true;
            }
        });
        _worker.setDaemon(true);
        _worker.start();
    } catch (Exception e) {
        _workerDone = true;
        s_logger.info("error occurred in initializing rdp client " + e.getMessage());
    }
}
Also used : PipelineImpl(streamer.PipelineImpl) InetSocketAddress(java.net.InetSocketAddress) ScreenDescription(common.ScreenDescription) SizeChangeListener(common.SizeChangeListener) Pipeline(streamer.Pipeline) AprSocketWrapperImpl(streamer.apr.AprSocketWrapperImpl) RdpBufferedImageCanvas(com.cloud.consoleproxy.rdp.RdpBufferedImageCanvas) SSLState(streamer.ssl.SSLState) RdpClient(rdpclient.RdpClient)

Example 2 with AprSocketWrapperImpl

use of streamer.apr.AprSocketWrapperImpl in project cloudstack by apache.

the class Client method runClient.

public void runClient(String[] args) {
    try {
        Protocol protocol = parseOptions(args);
        if (protocol == Protocol.NONE)
            return;
        System.setProperty("streamer.Link.debug", "" + debugLink.used);
        System.setProperty("streamer.Element.debug", "" + debugElement.used);
        System.setProperty("streamer.Pipeline.debug", "" + debugPipeline.used);
        SSLState sslState = new SSLState();
        // Create socket wrapper
        if ("jre".equals(sslImplementation.value)) {
            socket = new SocketWrapperImpl("socket", sslState);
        } else if ("apr".equals(sslImplementation.value)) {
            socket = new AprSocketWrapperImpl("socket", sslState);
        } else if ("bco".equals(sslImplementation.value)) {
            socket = new BcoSocketWrapperImpl("socket", sslState);
        } else {
            throw new RuntimeException("Unexpected option value: \"" + sslImplementation.value + "\". " + sslImplementation.help());
        }
        screen = new ScreenDescription();
        canvas = new BufferedImageCanvas(canvasWidth.value, canvasHeight.value);
        screen.addSizeChangeListener(new SizeChangeListener() {

            @Override
            public void sizeChanged(int width, int height) {
                if (canvas != null) {
                    canvas.setCanvasSize(width, height);
                    if (scroller != null)
                        scroller.setSize(canvas.getWidth(), canvas.getHeight());
                }
            }
        });
        assemblePipeline(setMainElementAndAddressBasedOnProtocol(protocol, sslState));
        frame = createVncClientMainWindow(canvas, protocol.toString() + " " + hostName.value, new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent evt) {
                shutdown();
            }
        });
        try {
            // Connect socket to remote server and run main loop(s)
            socket.connect(address);
        } finally {
            shutdown();
        }
    } catch (Exception e) {
        e.printStackTrace(System.err);
    }
}
Also used : WindowAdapter(java.awt.event.WindowAdapter) SocketWrapperImpl(streamer.SocketWrapperImpl) AprSocketWrapperImpl(streamer.apr.AprSocketWrapperImpl) BcoSocketWrapperImpl(streamer.bco.BcoSocketWrapperImpl) WindowEvent(java.awt.event.WindowEvent) AprSocketWrapperImpl(streamer.apr.AprSocketWrapperImpl) SSLState(streamer.ssl.SSLState) BcoSocketWrapperImpl(streamer.bco.BcoSocketWrapperImpl)

Aggregations

AprSocketWrapperImpl (streamer.apr.AprSocketWrapperImpl)2 SSLState (streamer.ssl.SSLState)2 RdpBufferedImageCanvas (com.cloud.consoleproxy.rdp.RdpBufferedImageCanvas)1 ScreenDescription (common.ScreenDescription)1 SizeChangeListener (common.SizeChangeListener)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 InetSocketAddress (java.net.InetSocketAddress)1 RdpClient (rdpclient.RdpClient)1 Pipeline (streamer.Pipeline)1 PipelineImpl (streamer.PipelineImpl)1 SocketWrapperImpl (streamer.SocketWrapperImpl)1 BcoSocketWrapperImpl (streamer.bco.BcoSocketWrapperImpl)1