Java Socket.getInputStream()
Syntax
Socket.getInputStream() has the following syntax.
public InputStream getInputStream() throws IOException
Example
In the following code shows how to use Socket.getInputStream() method.
// www. j a v a 2 s . c om
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
class Whois {
public static void main(String args[]) throws Exception {
int c;
Socket s = new Socket("internic.net", 43);
InputStream in = s.getInputStream();
OutputStream out = s.getOutputStream();
String str = "asdfasdfasdf\n";
byte buf[] = str.getBytes();
out.write(buf);
while ((c = in.read()) != -1) {
System.out.print((char) c);
}
s.close();
}
}