Write a program for connecting server with client like google.com with ip address of it.
// java socket client example
import java.io.*;
import java.net.*;
public class socket_client
{
Public static void main(String[] args) throws IOException
{
Socket s = new Socket();
String host = “www.google.com”;
Try
{
s.connect(new InetSocketAddress(host,80));
}
//Host not found
catch(UnknownHostException e)
{
System.out.println(“Dont know about this host: ” +host);
System.exit(1);
}
System.out.println(“Connected”);
}
}
import java.io.*;
import java.net.*;
public class socket_client
{
Public static void main(String[] args) throws IOException
{
Socket s = new Socket();
String host = “www.google.com”;
Try
{
s.connect(new InetSocketAddress(host,80));
}
//Host not found
catch(UnknownHostException e)
{
System.out.println(“Dont know about this host: ” +host);
System.exit(1);
}
System.out.println(“Connected”);
}
}
Comments
Post a Comment