Source Code : Read and write through socket

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Read and write through socket

      

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class Main {
  public static void whois(String query, String server) throws IOException {
    Socket sock = new Socket(server, 43);
    int c = 0;
    
    OutputStream os = sock.getOutputStream();
    InputStream is = sock.getInputStream();
    query += "
";
    os.write(query.getBytes("iso8859_1"));

    while (c != -1) {
      c = is.read();
      if (c != -1)
        System.out.println((char) c);
    }
  }

  public static void main(String[] args) throws Exception {
    String hostname = "whois.networksolutions.com";
    whois("query", hostname);
  }
}

   
    
    
    
    
    
  

Thank with us