Socket getOutputStream - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Socket getOutputStream method.

This code example shows how to use the following methods:getOutputStream
            if (dataSocket == null) {
                myLog.l(Log.INFO,
                        "dataSocketFactory.onTransfer() returned null"); 
                return false; 
            } 
            dataOutputStream = dataSocket.getOutputStream();
            return true; 
        } catch (IOException e) {
            myLog.l(Log.INFO,
                    "IOException getting OutputStream for data socket"); 
            dataSocket = null;
            return false; 
        } 
    } 
 
    public void quit() { 
        myLog.d("SessionThread told to quit");
        closeSocket(); 
    } 
 
7
CodeRank
This code example shows how to use the following methods:close, getInputStream, getOutputStream
		final FileOutputStream localFile = new FileOutputStream(DESTFILE);
		final RemoteControlWriter localWriter = new RemoteControlWriter(
				localFile);
 
		// Open a socket to the coverage agent: 
		final Socket socket = new Socket(InetAddress.getByName(ADDRESS), PORT);
		final RemoteControlWriter writer = new RemoteControlWriter(
				socket.getOutputStream());
		final RemoteControlReader reader = new RemoteControlReader(
				socket.getInputStream());
		reader.setSessionInfoVisitor(localWriter);
		reader.setExecutionDataVisitor(localWriter);
 
		// Send a dump command and read the response: 
		writer.visitDumpCommand(true, false);
		reader.read();
 
		socket.close();
		localFile.close();
	} 

7
CodeRank
This code example shows how to use the following methods:getInputStream, getOutputStream
This code example shows how to use the following methods:getInputStream, getOutputStream
 
    private void ftpConnect(String server, int portNum)
        throws IOException { 
        // Set up socket, control streams, connect to ftp server 
        // Open socket to server control port (default is 21) 
        csock = new Socket(server, portNum);
        // Open control streams 
        InputStream cis = csock.getInputStream();
        dcis =  new BufferedReader(new InputStreamReader(cis));
        OutputStream cos = csock.getOutputStream();
        pos = new PrintWriter(cos, true); // set auto flush true.
        // See if server is alive or dead... 
        String numerals = responseHandler(null); 
        if(numerals.substring(0,3).equals("220")) {
          // ftp server alive 
          // System.out.println("Connected to ftp server"); 
        }         
        else { 
          System.err.println("Error connecting to ftp server.");
        } 
7
CodeRank
This code example shows how to use the following methods:connect, getInputStream, getOutputStream
  public AbstractSocketClient(int port) {
    this.port = port;
  } 
 
  public final void connect() throws IOException {
    Socket socket = new Socket();
    socket.connect(new InetSocketAddress(port));
    InputStream in = socket.getInputStream();
    OutputStream out = socket.getOutputStream();
 
    // 
    this.socket = socket;
    this.in = in;
    this.out = out;
 
    // 
    handle(in ,out);
  } 
 
  protected abstract void handle(InputStream in, OutputStream out) throws IOException;
7
CodeRank
This code example shows how to use the following methods:getInputStream, getOutputStream
        long lastTime = System.currentTimeMillis();
 
        private static final int HEADER_SIZE = 24;
 
        public LogReader() throws IOException { 
            this.socket = new Socket("127.0.0.1", 5040);
            this.in = new DataInputStream(this.socket.getInputStream());
            // Write two newlines to indicate "no reader args" 
            this.socket.getOutputStream().write('\n');
            this.socket.getOutputStream().write('\n');
        } 
 
        public void run() { 
            while (active) {
                try { 
                    while (in.available() > 0) {
                        logger.write("Reading message.\n".getBytes());
 
                        int length = in.readInt();
                        byte[] bytes = new byte[length];
7
CodeRank
This code example shows how to use the following methods:close, getChannel, getInetAddress, getInputStream, getLocalAddress
import org.apache.hadoop.io.IOUtils; 
import org.apache.hadoop.ipc.Server; 
import org.apache.hadoop.security.token.Token; 
 
@InterfaceAudience.Private 
public class TcpPeerServer implements PeerServer { 
  static final Log LOG = LogFactory.getLog(TcpPeerServer.class);
 
  private final ServerSocket serverSocket;
 
  public static Peer peerFromSocket(Socket socket)
      throws IOException {
    Peer peer = null;
    boolean success = false;
    try { 
      // TCP_NODELAY is crucial here because of bad interactions between 
      // Nagle's Algorithm and Delayed ACKs. With connection keepalive 
      // between the client and DN, the conversation looks like: 
      //   1. Client -> DN: Read block X 
      //   2. DN -> Client: data for block X 

7
CodeRank
This code example shows how to use the following methods:getInputStream, getOutputStream, setTcpNoDelay
 
    public TcpConnector connect() { 
        if (isClosed()) { 
            log.infof("Connect socket <-> %s:%d", host, port);
            try { 
                socket = new Socket(InetAddress.getByName(host), port);
                socket.setTcpNoDelay(true);
                reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                writer = new OutputStreamWriter(socket.getOutputStream());
            } 
            catch (UnknownHostException e) {
                log.warnf("Unknown host '%s:%d'", host, port);
                throw Lang.wrapThrow(e);
            } 
            catch (IOException e) {
                log.warnf("IOError '%s:%d'", host, port);
                throw Lang.wrapThrow(e);
            } 
        } 
        return this;
7
CodeRank
This code example shows how to use the following methods:getInputStream, getOutputStream
     * @param socket 
     *            The underlying socket. 
     */ 
    protected AJP13Connection createConnection(Socket socket) throws IOException
    { 
        return new AJP13Connection(this,socket.getInputStream(),socket.getOutputStream(),socket,getBufferSize());
    } 
 
    /* ------------------------------------------------------------ */ 
    /** 
     * Customize the request from connection. This method extracts the socket 
     * from the connection and calls the customizeRequest(Socket,HttpRequest) 
     * method. 
     *  
     * @param request 
     */ 
    public void customizeRequest(HttpConnection connection, HttpRequest request)
    { 
        if (_identifyListener)
            request.setAttribute(HttpListener.ATTRIBUTE,getName());
7
CodeRank
This code example shows how to use the following methods:getOutputStream
 
    private static boolean writeValue(Socket client, String value) {
        boolean result;
        BufferedWriter out = null;
        try { 
            OutputStream clientStream = client.getOutputStream();
            out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
            out.write(value);
            out.write("\n");
            out.flush();
            result = true;
        } catch (Exception e) {
            result = false;
        } finally { 
            if (out != null) {
                try { 
                    out.close();
                } catch (IOException e) {
                    result = false;
                } 
7
CodeRank

Related Socket getOutputStream Questions & Answers:

getOutputStream Method Overview
Returns an output stream for this socket.
See Code Examples for other Java 8 Socket Methods: