Socket: getOutputStream() throws IOException


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();
  }
}
Home 
  Java Book 
    Networking  

Socket:
  1. Socket
  2. new Socket(InetAddress address, int port) throws IOException
  3. Socket: connect(SocketAddress endpoint, int timeout) throws IOException
  4. Socket: getInputStream() throws IOException
  5. Socket: getLocalSocketAddress()
  6. Socket: getOutputStream() throws IOException
  7. Socket: getRemoteSocketAddress()
  8. Socket: readUTF() and writeUTF(String str)