*****SOCKET-C****
import java.io.*;
import java.net.*;
import java.lang.String;
public class clientecho1
{
public static void main(String args[])throws Exception
{
DataInputStream in=new DataInputStream(System.in);
Socket s=new Socket("localhost",1234);
DataInputStream inecho=new DataInputStream(s.getInputStream());
DataOutputStream out=new DataOutputStream(s.getOutputStream());
String str;
System.out.println("client side");
System.out.println("\n type exit to quit");
System.out.println("\n enter the client msg:");
while((str=in.readLine())!=null)
{
out.writeBytes(str+"\n");
if(str.equals("exit"))
{
out.writeBytes("\n client terminated");
break;
}
else
{
System.out.println("echo from server:");
System.out.println(inecho.readLine());
System.out.println("\n enter client msg:");
}
}
}
}
No comments:
Post a Comment