473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

sreekandank
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
0 1533

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

Similar topics

4
by: Sherman Willden | last post by:
I am trying to use Perl's XML::Twig to modify a version number in an XML document. At the very end of this posting is an excerpt from the xml document. Just before the xml excerpt is the Perl code...
1
by: LC's No-Spam Newsreading account | last post by:
I have the following arrangement working under Netscape 3 / Unix, IE6 / Win and Konqueror / Linux, but NOT under Netscape 7 Unix or Mozilla Linux (silently fails) nor under Netscape 4 Unix (fails...
13
by: python | last post by:
hello and thanks for reading this, i have been a dos/windows user using some form of the basic language for 30 years now. i own and run a small programming company and there is one feature that...
12
by: SStory | last post by:
Doing pages for contract..... If I make an ASPX file that does certain things, how simple would it be for a person who know nothing about it to modify the user interface without bothering the...
9
by: amyxmas | last post by:
I am trying to write a routine which follows this logic, but not sure how to implement: <script> xxx = "... apple green yellow blue ..."; {right here I need to modify part of the string, so...
4
by: gll | last post by:
Can anyone tell me, how I can get in java the packet of IP and then modify it? Maybe there is a special library, which could help me? Thank you in advance. Gregory
2
by: gusa992000 | last post by:
Hello I am trying the following problem: A web app in jsp and java has to open a microsoft word document directly in the browser. This part is easy and i have done it. The user then can...
23
by: no1zson | last post by:
I have been adding buttons to my GUI to manipulate list data. I added a Delete button this morning in case I decide I no longer needed a particular element. I am now working on a modify button, in...
1
by: alireza6485 | last post by:
Hi, I have the following code,it prints out a 5 by 5 matrix and puts "-" in each location. I need to ask user for the number of * they like to put in the matrix and based on the number they enter...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.