CLIENT.JAVA
import java.io.*;
import java.net.*;
public class Client{
public static void main(String args[]){
try{
//BufferedReader inFromUser=new BufferedReader(new InputStreamReader(System.in));
Socket clientSocket=new Socket("16.138.53.77",1234);
InputStreamReader stream=new InputStreamReader(clientSocket.getInputStream());
PrintWriter writer=new PrintWriter(clientSocket.getOutputStream());
writer.println("hi");
BufferedReader reader=new BufferedReader(stream);
String message=reader.readLine();
System.out.println("received from server " +message);
clientSocket.close();
}catch(IOException e){
System.out.println(e);
}
}
}
SERVER.JAVA
import java.io.*;
import java.net.*;
public class Server{
public static void main(String args[]){
String clientSentence;
try{
ServerSocket sock=new ServerSocket(1234);
while(true){
Socket connectionSocket=sock.accept();
BufferedReader inFromClient=new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream outToClient=new DataOutputStream(connectionSocket.getOutputStream());
clientSentence=inFromClient.readLine();
System.out.println("sgh" +clientSentence);
outToClient.writeBytes("Hello");
outToClient.close();
sock.close();
}
}catch(IOException e){
System.out.println(e);
}
}
}
INETADDRESS
import java.net.*;
public class F1
{
public static void main(String args[]) throws UnknownHostException {
InetAddress Address = InetAddress.getLocalHost();
System.out.println(Address);
}
}
import java.io.*;
import java.net.*;
public class Client{
public static void main(String args[]){
try{
//BufferedReader inFromUser=new BufferedReader(new InputStreamReader(System.in));
Socket clientSocket=new Socket("16.138.53.77",1234);
InputStreamReader stream=new InputStreamReader(clientSocket.getInputStream());
PrintWriter writer=new PrintWriter(clientSocket.getOutputStream());
writer.println("hi");
BufferedReader reader=new BufferedReader(stream);
String message=reader.readLine();
System.out.println("received from server " +message);
clientSocket.close();
}catch(IOException e){
System.out.println(e);
}
}
}
SERVER.JAVA
import java.io.*;
import java.net.*;
public class Server{
public static void main(String args[]){
String clientSentence;
try{
ServerSocket sock=new ServerSocket(1234);
while(true){
Socket connectionSocket=sock.accept();
BufferedReader inFromClient=new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream outToClient=new DataOutputStream(connectionSocket.getOutputStream());
clientSentence=inFromClient.readLine();
System.out.println("sgh" +clientSentence);
outToClient.writeBytes("Hello");
outToClient.close();
sock.close();
}
}catch(IOException e){
System.out.println(e);
}
}
}
INETADDRESS
import java.net.*;
public class F1
{
public static void main(String args[]) throws UnknownHostException {
InetAddress Address = InetAddress.getLocalHost();
System.out.println(Address);
}
}
Post a Comment