How to modify this java code......?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sreekandank
    New Member
    • Jun 2009
    • 45

    How to modify this java code......?

    Hi.....
    I have done the program for simple chat application in java....as given below....

    server.java

    import java.net.*;
    import java.io.*;
    public class server
    {
    public static void main(String args[])throws Exception
    {
    ServerSocket ss=new ServerSocket(30 0);
    Socket s=ss.accept();
    System.out.prin tln("Server is Ready:");
    DataInputStream dis=new DataInputStream (s.getInputStre am());
    PrintStream ps=new PrintStream(s.g etOutputStream( ));
    while(true)
    {
    String st=dis.readLine ();
    System.out.prin tln(st);
    st=new DataInputStream (System.in).rea dLine();
    ps.println("Ser ver says:"+st);

    }
    }
    }

    client.java

    import java.net.*;
    import java.io.*;
    public class client
    {
    public static void main(String args[])throws Exception
    {
    InetAddress ina=InetAddress .getLocalHost() ;
    Socket s=new Socket(ina,300) ;
    System.out.prin tln("Client is Ready:");
    DataInputStream dis=new DataInputStream (s.getInputStre am());
    PrintStream ps=new PrintStream(s.g etOutputStream( ));
    while(true)
    {
    String st=new DataInputStream (System.in).rea dLine();
    ps.println("Cli ent says:"+st);
    st=dis.readLine ();
    System.out.prin tln(st);
    }
    }
    }

    Now i want to modify this program that....
    If the client send the requests more than 2 times, through the same socket the server should send a response saying "GOOD BYE" and should not respond for any further request.....To implement that program in such a way....How to modify that program....?So kindly assist me on that...
Working...