Socket getOutputStream Example

Socket class getOutputStream example. This example shows you how to use getOutputStream method.


Socket class getOutputStream example. public OutputStream getOutputStream() throws IOException Returns an output stream for this socket. If this socket has an associated channel then the resulting output stream delegates all of its operations to the channel. If the channel is in non-blocking mode then the output stream's write operations will throw an IllegalBlockingModeException.

Here is the code
/*
 * @ # GetOutputStream.java
 * A class repersenting use to getOutputStream method 
 * of NumberFormat class in java.text package
 * version 17 June 2008
 * author Rose India 
 */

import java.net.*;
import java.io.*;

public class GetOutputStream {

    public static void main(String args[]) throws Exception {

        byte buff[] new byte[221];
        InetAddress addr = InetAddress.getByName("192.168.10.211");
        Socket s = new Socket(addr, 8080);


        OutputStream output = s.getOutputStream();
        InputStream input = s.getInputStream();
        String GetCmd = "GET /index.html HTTP/1.0\r\n\r\n";
        GetCmd.getBytes(0, GetCmd.length(), buff, 0);
        output.write(buff);
        input.read(buff, 0, buff.length);
        System.out.println(new String(buff, 0));

    }
}

Output
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
ETag: W/"8144-1201559975000"
Last-Modified: Mon, 28 Jan 2008 22:39:35 GMT
Content-Type: text/html
Content-Length: 8144
Date: Fri, 20 Jun 2008 10:23:30 GMT
Connection: close

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US