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”);
}
}
Very useful and informative content! I really appreciate the way you explained the concepts in a simple and clear manner. For learners who want practical exposure and hands-on experience, the Best Java Real Time Projects Online Training is a great option to build industry-level skills. Thank you for sharing such valuable information!
ReplyDeleteGreat explanation of Java fundamentals in this post. Having a clear understanding of core Java concepts helps developers write efficient and maintainable code. Those interested in strengthening their basics can check Core JAVA Online Training for practical learning experience.
ReplyDelete