Channel from Socket - Java java.nio.channels

Java examples for java.nio.channels:SocketChannel

Description

Channel from Socket

Demo Code


import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.SocketException;

public class Main{
    public static Channel fromSocket(Socket sock) throws IOException {
        InputStream socket_in;/*from  w  ww  .j  ava 2  s  .  c o m*/
        OutputStream buffered_out;

        socket_in = new SocketInputStream(sock.getInputStream());
        buffered_out = new BufferedOutputStream(sock.getOutputStream());
        sock.setKeepAlive(true);

        return new Channel(socket_in, buffered_out);
    }
}

Related Tutorials