Socket shutdownInput Example

Started by VelMurugan, Jan 02, 2009, 06:56 AM

Previous topic - Next topic

VelMurugan

Socket shutdownInput Example

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

Socket class shutdownInput example. public void shutdownInput() throws IOException Places the input stream for this socket at "end of stream". Any data sent to the input stream side of the socket is acknowledged and then silently discarded.

Here is the code

/*
* @ # ShutdownInput.java
* A class repersenting use to shutdownInput method
* of Socket class in java.net package
* version 17 June 2008
* author Rose India
*/

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

public class ShutdownInput {

    public static void main(String args[]) throws Exception {
        byte buff[] = new byte[64];
        InetAddress addr = InetAddress.getByName("192.168.10.222");
        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));
        s.shutdownInput();
        s.shutdownOutput();
    }
}


Output
Quote
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
ETag: W/"7347-118489

Source : codingdiary