public Connection(Socket socket) throws IOException { this(SocketChannelStream.in(socket),SocketChannelStream.out(socket)); }
Connection c = new Connection(SocketChannelStream.in(s),out);
new BufferedInputStream(SocketChannelStream.in(s)), new BufferedOutputStream(SocketChannelStream.out(s)),null,p);
public LegacyJnlpConnectionState(Socket socket, List<? extends JnlpConnectionStateListener> listeners) throws IOException { super(socket, listeners); socketOutputStream = SocketChannelStream.out(socket); this.bufferedOutputStream = new BufferedOutputStream(socketOutputStream); socketInputStream = SocketChannelStream.in(socket); this.dataInputStream = new DataInputStream(socketInputStream); this.printWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF-8")), true); }
public Channel build(Socket s) throws IOException { // support half-close properly return build(new BufferedInputStream(SocketChannelStream.in(s)), new BufferedOutputStream(SocketChannelStream.out(s))); }
private void runOnSocket(Socket s) throws IOException, InterruptedException { // this prevents a connection from silently terminated by the router in between or the other peer // and that goes without unnoticed. However, the time out is often very long (for example 2 hours // by default in Linux) that this alone is enough to prevent that. s.setKeepAlive(true); // we take care of buffering on our own s.setTcpNoDelay(true); main(new BufferedInputStream(SocketChannelStream.in(s)), new BufferedOutputStream(SocketChannelStream.out(s)), mode,ping, jarCache != null ? new FileSystemJarCache(jarCache,true) : null); }
public Channel build(SocketChannel s) throws IOException { return build( SocketChannelStream.in(s), SocketChannelStream.out(s)); }
public OutputStream connect(OutputStream out) throws IOException { Socket s = new Socket(remoteHost, remotePort); try (InputStream in = SocketChannelStream.in(s)) { new CopyThread( String.format("Copier to %s:%d", remoteHost, remotePort), in, out, () -> { try { s.close(); } catch (IOException e) { LOGGER.log(Level.WARNING, "Problem closing socket for ForwardingFactory", e); } }).start(); } return new RemoteOutputStream(SocketChannelStream.out(s)); }
public void run() { try (InputStream in = SocketChannelStream.in(s); OutputStream out = forwarder.connect(new RemoteOutputStream(SocketChannelStream.out(s)))) { new CopyThread( "Copier for " + s.getRemoteSocketAddress(), in, out, () -> { try { s.close(); } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to close socket", e); } }).start(); } catch (IOException e) { // this happens if the socket connection is terminated abruptly. LOGGER.log(FINE,"Port forwarding session was shut down abnormally",e); } } }.start();
public static InputStream in(Socket s) throws IOException { if (s.getChannel()!=null) return in(s.getChannel()); else return new SocketInputStream(s); }
/** * Creates the best network layer for the provided {@link Socket}. * * @param socket the {@link Socket}. * @return the best {@link NetworkLayer} for the provided {@link Socket}. * @throws IOException if the socket is closed already. */ private NetworkLayer createNetworkLayer(Socket socket) throws IOException { NetworkLayer networkLayer; SocketChannel socketChannel = isPreferNio() ? socket.getChannel() : null; if (socketChannel == null) { networkLayer = new BIONetworkLayer(ioHub, Channels.newChannel(SocketChannelStream.in(socket)), Channels.newChannel(SocketChannelStream.out(socket))); } else { networkLayer = new NIONetworkLayer(ioHub, socketChannel, socketChannel); } return networkLayer; }
/** * Creates the best network layer for the provided {@link Socket}. * * @param socket the {@link Socket}. * @return the best {@link NetworkLayer} for the provided {@link Socket}. * @throws IOException if the socket is closed already. */ private NetworkLayer createNetworkLayer(Socket socket) throws IOException { NetworkLayer networkLayer; SocketChannel socketChannel = isPreferNio() ? socket.getChannel() : null; if (socketChannel == null) { networkLayer = new BIONetworkLayer(ioHub, Channels.newChannel(SocketChannelStream.in(socket)), Channels.newChannel(SocketChannelStream.out(socket))); } else { networkLayer = new NIONetworkLayer(ioHub, socketChannel, socketChannel); } return networkLayer; }
public static void main(String[] args) throws Exception { ServerSocket ss = new ServerSocket(PORT); while (true) { System.out.println("Ready"); Socket s = ss.accept(); s.setTcpNoDelay(true); System.out.println("Accepted"); Channel ch = new Channel("bogus", Executors.newCachedThreadPool(), new BufferedInputStream(SocketChannelStream.in(s)), new BufferedOutputStream(SocketChannelStream.out(s))); ch.join(); s.close(); } } public static final int PORT = 9532;
@Override public void run() { try { DataInputStream dis = new DataInputStream(SocketChannelStream.in(fromClient)); String header = dis.readUTF(); if (header.equals("Protocol:" + handler.getName())) { handler.handle(fromClient.socket(), new HashMap<String, String>(), serverListener) .get(); if (config.server && clientCount.incrementAndGet() >= config.numClients) { stats.clientsStarted(); } } else { fromClient.close(); } } catch (IOException e) { e.printStackTrace(System.err); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } } });
new BufferedInputStream(SocketChannelStream.in(s)), new BufferedOutputStream(SocketChannelStream.out(s)),null,p);
/** * Launches RC in a separate JVM. * * @param standaloneServerJar * The jar file of the grid to launch. */ static public Channel createSeleniumRCVM(File standaloneServerJar, File htmlUnitDriverJar, TaskListener listener, Map<String, String> properties, Map<String, String> envVariables) throws IOException, InterruptedException { String displayName = "Selenium RC"; ClasspathBuilder classpath = new ClasspathBuilder().add(standaloneServerJar); // add htmlunit to classpath classpath.add(htmlUnitDriverJar); JVMBuilder vmb = new JVMBuilder(); vmb.systemProperties(properties); ServerSocket serverSocket = new ServerSocket(); serverSocket.bind(new InetSocketAddress("localhost", 0)); serverSocket.setSoTimeout(10000); // use -cp + FQCN instead of -jar since remoting.jar can be rebundled // (like in the case of the swarm plugin.) vmb.classpath().addJarOf(Channel.class); vmb.mainClass(Launcher.class); vmb.args().add("-cp").add(classpath); vmb.args().add("-connectTo", "localhost:" + serverSocket.getLocalPort()); // TODO add XVFB options here Proc p = vmb.launch(new LocalLauncher(listener)).stdout(listener).envs(envVariables).start(); Socket s = serverSocket.accept(); serverSocket.close(); return createChannel("Channel to " + displayName, Computer.threadPoolForRemoting, new BufferedInputStream(SocketChannelStream.in(s)), new BufferedOutputStream(SocketChannelStream.out(s)), null, p); }
public static void main(String[] args) throws Exception { byte[] payload = getRandomSequence(); byte[] digest = digest(new ByteArrayInputStream(payload)); while (true) { Socket s = new Socket("127.0.0.2",Receiver.PORT); s.setTcpNoDelay(true); Channel ch = new Channel("bogus", Executors.newCachedThreadPool(), new BufferedInputStream(SocketChannelStream.in(s)), new BufferedOutputStream(SocketChannelStream.out(s))); final Pipe p = Pipe.createLocalToRemote(); Future<byte[]> f = ch.callAsync(new DigestCallable(p)); System.out.println("Started"); long start = System.nanoTime(); IOUtils.copy(new ByteArrayInputStream(payload),p.getOut()); p.getOut().close(); f.get(); System.out.println("Done: "+ TimeUnit.NANOSECONDS.toMillis(System.nanoTime()-start)); assertArrayEquals(digest, f.get()); // verify the correctness of the result ch.close(); ch.join(); s.close(); } }