0% found this document useful (0 votes)
30 views1 page

Echo Client

This Java code defines an EchoClient class that creates a socket connection to the local host on port 9000 and allows for bidirectional communication by reading from standard input and the socket input stream, and writing to the socket output stream.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views1 page

Echo Client

This Java code defines an EchoClient class that creates a socket connection to the local host on port 9000 and allows for bidirectional communication by reading from standard input and the socket input stream, and writing to the socket output stream.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.net.

*;
import java.io.*;
public class EchoClient
{
public static void main(String arg[])
{

try
{

String line;
InetAddress ip = InetAddress.getLocalHost();
Socket soc = new Socket(ip, 9000);
BufferedReader socIn = new BufferedReader(new
InputStreamReader(soc.getInputStream()));
PrintStream socOut = new PrintStream(soc.getOutputStream());
BufferedReader keyIn = new BufferedReader(new InputStreamReader(System.in));
while(true)
{

System.out.print("Client:"); line = keyIn.readLine();


socOut.println(line);
System.out.println("Server:" + socIn.readLine());
}

}
catch(IOException e)
{
System.out.println(e);
}
}
}

You might also like