import [Link].
*;
import [Link].*;
public class SocketClient {
private Socket socket;
private DataInputStream consoleInput; // from keyboard
private DataOutputStream out; // to server
private DataInputStream in; // from server
public SocketClient(String address, int port) {
try {
socket = new Socket(address, port);
[Link]("Connected to server");
consoleInput = new DataInputStream([Link]);
out = new DataOutputStream([Link]());
in = new DataInputStream([Link]());
String line = "";
while () {
// send message to server
[Link]("You: ");
line = [Link]();
[Link](line);
if ([Link]("End")) break;
// wait for server reply
String response = [Link]();
[Link]("Server: " + response);
}
// close resources
[Link]();
[Link]();
[Link]();
[Link]();
} catch (IOException e) {
[Link]("Error: " + [Link]());
}
}
public static void main(String[] args) {
new SocketClient("[Link]", 5000);
}
}
import [Link].*;
import [Link].*;
public class SocketServer {
private Socket socket;
private ServerSocket server;
private DataInputStream in; // from client
private DataOutputStream out; // to client
private DataInputStream consoleIn; // from server keyboard
public SocketServer(int port) {
try {
server = new ServerSocket(port);
[Link]("Server started. Waiting for client...");
socket = [Link]();
[Link]("Client connected");
in = new DataInputStream([Link]());
out = new DataOutputStream([Link]());
consoleIn = new DataInputStream([Link]);
String line = "";
while () {
// wait for client message
line = [Link]();
[Link]("Client: " + line);
if ([Link]("End")) break;
// send reply to client
[Link]("Server: ");
String response = [Link]();
[Link](response);
}
// close resources
[Link]();
[Link]();
[Link]();
[Link]();
[Link]();
} catch (IOException e) {
[Link]("Error: " + [Link]());
}
}
public static void main(String[] args) {
new SocketServer(5000);
}
}
import [Link].*;
public class InetAddressExample1 {
public static void main(String[] args) throws UnknownHostException{
// To get and print InetAddress of the Local Host
InetAddress address = [Link]();
[Link]("InetAddress of the Local Host : "+address);
// To get and print host name of the Local Host
String hostName=[Link]();
[Link]("\nHost name of the Local Host : "+hostName);
import [Link].*;
public class InetAddressExample2 {
public static void main(String[] args)
throws UnknownHostException
{
// To get and print InetAddress of Named Hosts
InetAddress address1 = [Link](
"[Link]");
[Link]("Inet Address of named hosts : "
+ address1);
// To get and print ALL InetAddress of Named Host
InetAddress arr[] = [Link](
"[Link]");
[Link]("\nInet Address of ALL named hosts :");
for (int i = 0; i < [Link]; i++) {
[Link](arr[i]);
}
}
}