By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,934 Members | 1,677 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,934 IT Pros & Developers. It's quick & easy.

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

sreekandank
P: 45
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(300);
Socket s=ss.accept();
System.out.println("Server is Ready:");
DataInputStream dis=new DataInputStream(s.getInputStream());
PrintStream ps=new PrintStream(s.getOutputStream());
while(true)
{
String st=dis.readLine();
System.out.println(st);
st=new DataInputStream(System.in).readLine();
ps.println("Server 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.println("Client is Ready:");
DataInputStream dis=new DataInputStream(s.getInputStream());
PrintStream ps=new PrintStream(s.getOutputStream());
while(true)
{
String st=new DataInputStream(System.in).readLine();
ps.println("Client says:"+st);
st=dis.readLine();
System.out.println(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...
Aug 12 '09 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.