import java.io.*;
import java.net.*;
class Client_1
{
public static void main (String[] args)
{
int port =6543;
String add=”localhost”;
try
{
InetAddress ia=InetAddress.getByName(add);
Socket socket =new Socket(add,port);
InputStream input=socket.getInputStream();
OutputStream output=socket.getOutputStream();
DataInputStream in=new DataInputStream(input);
DataOutputStream out=new DataOutputStream(output);
BufferedReader enter=new BufferedReader(new InputStreamReader(System.in));
String line=null;
while(true)
{
System.out.print(“Message to server : “);
line=enter.readLine();
out.writeUTF(line);
out.flush();
line=in.readUTF();
System.out.println(“Message from server : ” + line);
}
}
catch (Exception ex)
{
}
}
}
import java.io.*;
class ser2 im
{
}
class Server_1
{
public static void main (String[] args)
{
int port = 6543;
try
{
ServerSocket ss = new ServerSocket(port);
System.out.println(“Waiting for client:: “);
Socket socket=ss.accept();
System.out.println(“Client found… “);
InputStream input=socket.getInputStream();
OutputStream output=socket.getOutputStream();
DataInputStream in=new DataInputStream(input);
DataOutputStream out=new DataOutputStream(output);
BufferedReader enter=new BufferedReader(new InputStreamReader(System.in));
String line=null;
while(true)
{
line=in.readUTF();
System.out.println(“Message From Client:: “+line);
System.out.print(“Message to Client : “);
line=enter.readLine();
out.writeUTF(line);
out.flush();
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
Leave a Reply