How to modify below simple chat system?Please help!

Dear,
I have a ChatServer.java files as below. It is a round robin chating system. There are two client chatting. Now I want to modify below file that allow the discussion to keep going until one of the user input is "BYE" in uppercase without any preceding and trailing characters. After one user input of "BYE" will terminates everyone else including the server. How do I modifty? Please help!
import java.io.*;
import java.net.*;
public class ChatServer.java
// Valid PORT_NUMBER ranges from 1 to 65,535. However the numbers from 1 to 1023
// are reserved, for example, 80 is reserved for http.
private final static int PORT_NUMBER = 3030;
public static void main (String[] args) throws IOException
Socket socket1, socket2;
DataInputStream dataIn1, dataIn2;
DataOutputStream dataOut1, dataOut2;
String line;
System.out.println ( "\r\n-- Server Started --\r\n" );
// We need to create a ServerSocket at a free port number.
ServerSocket server = new ServerSocket ( PORT_NUMBER );
// Calling the accept method, the server waits for a client to make a TCP connection.
socket1 = server.accept ();
socket2 = server.accept ();
// ServerSocket is only needed to handle connection request. Once the connection
// is made, the ServerSocket can be closed even the sockets remain open.
// Normally, the ServerSocket won't be closed this early because real applications
// are designed to handle arbitrarily many clients. However we only handle two.
server.close ();
try
// There should be a pair of input and output streams for each socket.
// The output stream of the server corresponds to the input stream of the client.
// Therefore if we send a line on the output stream, the client should read
// the line in the corresponding input stream.
dataIn1 = new DataInputStream (new BufferedInputStream (socket1.getInputStream ()));
dataOut1 = new DataOutputStream (new BufferedOutputStream (socket1.getOutputStream ()));
dataIn2 = new DataInputStream (new BufferedInputStream (socket2.getInputStream ()));
dataOut2 = new DataOutputStream (new BufferedOutputStream (socket2.getOutputStream ()));
for ( int i=0; i < 3; i++)
// Read a line from the client 1
line = dataIn1.readUTF ( );
// Write a line to client 2
dataOut2.writeUTF ( line );
dataOut2.flush ( );
// Show the line on the server's screen
System.out.println ( "\r\nClient 1: " + line);
System.out.flush( );
// Read a line from the client 2
line = dataIn2.readUTF ( );
// Write a line to client 1
dataOut1.writeUTF ( line );
dataOut1.flush ( );
// Show the line on the server's screen
System.out.println ( "Client 2: " + line);
System.out.flush( );
catch (IOException ex)
throw ex;
finally
System.out.println ("\r\n-- Shutdown --");
socket1.close ();
socket2.close ();

In this section here do this:
The chat client 1:
// Show the line on the server's screen
String printTheLine="\r\nClient 1:" + line;
System.out.println (printTheLine);
System.out.flush( );
if(printTheLine.equals("\r\nClient 1:BYE"){
//exit prog
}Client 2
// Show the line on the server's screen
String printTheLine="\r\nClient 2:" + line;
System.out.println (printTheLine);
System.out.flush( );
if(printTheLine.equals("\r\nClient 2:BYE"){
//exit prog
}All you have to do is exit the prog. I am not sure if you need in the .eguals part (when you are comparing the strings), the \r\n. Anyway, once you put the code to exit your prog in the if conditionals, it will exit if the output on the screen looks like:
Client 1:BYE or
Client 2:BYE
If this helps, could I have some duke dollars?
Virum

Similar Messages

  • Hi,i was about to update my software version of i phone 4,but suddnley power went off.now my phone is not recognised ,and my phone doesn't work,how to reinstall operating system,please help me.....

    hi,i was about to update my software version of i phone 4,but suddnley power went off.now my phone is not recognised ,and my phone doesn't work,how to reinstall operating system,please help me.....

    Put the device in DFU mode: http://www.iclarified.com/entry/index.php?enid=1034

  • My ebay toolbar and the ebay logo that was in my system tray at the bottom have both disappeared when I installed FireFox??? How do I get them back? Please help.

    my ebay toolbar and the ebay logo that was in my system tray at the bottom have both disappeared when I installed FireFox??? How do I get them back? Please help.

    Option 1
    Back Up and try rebuild the library: hold down the command and option (or alt) keys while launching iPhoto. Use the resulting dialogue to rebuild. Choose to Repair Database. If that doesn't help, then try again, this time using Rebuild Database.
    If that fails:
    Option 2
    Download iPhoto Library Manager and use its rebuild function. (In Library Manager it's the FIle -> Rebuild command)
    This will create an entirely new library. It will then copy (or try to) your photos and all the associated metadata and versions to this new Library, and arrange it as close as it can to what you had in the damaged Library. It does this based on information it finds in the iPhoto sharing mechanism - but that means that things not shared won't be there, so no slideshows, books or calendars, for instance - but it should get all your events, albums and keywords, faces and places back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one. 
    Regards
    TD 

  • I accidentally dropped my firewall, or openned it.  I checked it in system preferences and it is turned off but I can not find how to put it back up.  PLEASE HELP!

    I accidentally dropped my firewall, or openned it.  I checked it in system preferences and it is turned off but I can not find how to put it back up.  PLEASE HELP!  I obviously do not want to leave this open very long, if you get my drift.

    Did you "click the lock to make changes"

  • I recently bought a dbx hardware compressor and am not quite sure how to use it in logic express 9. I hav a focusrite saffire 6 usb audio interface and am not dont how to use it in logic. Please help???

    I recently bought a dbx hardware compressor and am not quite sure how to use it in logic express 9. I hav a focusrite saffire 6 usb audio interface and am not dont how to use it in logic. Please help???

    MUYconfundido wrote:
    Pancenter,
    Thanks for the response, but I do not have a midi interface. I am using a midi to usb connector cable, thus bypassing the need for a Midi interface.
    The Mac reads the USB cable as a midi device, but not the keyboard that I am trying to use as a controller. I have tried it with my korg sp 300 and with my Nord Electro 2.
    Thoughts?
    Thanks,
    Tristan
    Tristan...
    This is what you have, correct?
    http://www.alesis.com/usbmidicable
    This from Alesis..
    "The AudioLink Series USB cable receives and outputs MIDI signal thanks to its internal interface. The USB-MIDI Cable connects plug-and-play to your Mac or PC for an all-in-one USB-MIDI solution."
    Notice, -internal interface-. What you have is a simple USB MIDI Interface. Most MIDI interfaces are USB.
    My point is (was), MIDI OUT of the Korg goes to the connector marked MIDI IN on the Alesis, those new to MIDI often get this wrong.
    pancenter-

  • How to acess Database in I18N? Please help.

    How to acess Database in I18N? Please help.

    I have tried to overide the getContents() method of ListResourceBundle class but it returning an error at run time saying null Pointer exception.
    Here are the 2 codes resp.
    import java.util.*;
    public class Test1
         static String string ;
         public static void main(String args[])
    Locale locale = Locale.ENGLISH;
    ResourceBundle myResources =
    ResourceBundle.getBundle("MyResources", locale);
    string = myResources.getString("HelpKey");
    System.out.println(string);
    import java.util.*;
    import java.sql.*;
    public class MyResources extends ListResourceBundle
         static String[][] s3= null;
    String s6= null;
         String s7= null;
    public Object[][] getContents()
    Object[][] obj= (Object[][])dataBase();
              for(int i= 0; i< obj.length;++i){
                   for(int j = 0;j<obj.length;++j){
                        System.out.println("GGGGGGGG obj["+i+"]["+j+"]"+obj[i][j]);
              //s6=(String)obj[0][0];
         //     s6= obj[0][0].toString();
              //s7=obj[1][0].toString();
    Object[][] contents = { {s6},{s7}};
         return contents;
         private static String[][] dataBase()
         {           try
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   Connection con=DriverManager.getConnection("jdbc:odbc:DSN");
                   PreparedStatement stat= con.prepareStatement("Select Value,Key from Table1 where Key= ?");
                   String s1= "HelpKey";
                   stat.setString(1,s1);
                   ResultSet rs= stat.executeQuery();
                   while(rs.next())
                        String s2= (String)rs.getString("Key");
                        String s4= (String)rs.getString("Value");
                        String[][] s3 ={{s2},{s4}};
              catch(Exception e)
              e.printStackTrace();
         return s3;

  • TS3694 How do i fix error 3194? please help!

    How do i fix error 3194? please help!

    iOS of your iPhone could be modified / hacked. No one will be able to support you in this Forum.

  • On my menu bar there is a American Flag icon and i do not know how to remove it??? Please help!!!

    On my menu bar there is a American Flag icon and i do not know how to remove it??? Please help!!!

    This is the input Menubar extra.
    Open your System Prefs, then select the Keyboard PreferencePane.  Click on the Input Sources Tab and on the bottom you shoudl see a checkmark next to Show Input menu..  Just uncheck it.

  • HT2515 When I'm on iChat, it doesn't show the video chat icon. When I try to change it, it tells me my camera doesn't support video chats. Please help :(

    When I'm on iChat, it doesn't show the video chat icon. When I try to change it, it tells me that my camera doesn't support video chats. Please help

    A lot of folks fix these kinds of issues with a simple re-start of the phone.
    Regards
    TD

  • HT1212 I have an ipod 4 touch with a broken power button and Im locked out of the ipod. How can I reset the ipod? Please help!

    I have an ipod 4 touch with a broken power button and Im locked out of the ipod. How can I reset the ipod? Please help!
    I also don't know the operating system.

    See the method in my reply in this discussion for how to place the iPod in Recovery mode w/o buttons
    Turn on without Home/Power Button

  • ITunes wont open for me. it keeps saying "the Disc "untitled playlist" cannot be read. An unknown error occurred (-69)." don't know how to get it to work. Please help

    iTunes wont open for me. it keeps saying "the Disc "untitled playlist" cannot be read. An unknown error occurred (-69)." don't know how to get it to work. Please help

    It is likely a hardware failure
    http://support.apple.com/kb/TS3694?viewlocale=en_US#error1

  • TS4605 Hi, I was working in WORD on a file containing huge data. My machine just hung up one day while working and now I seem to have lost the file how do I get it back.  Please HELP me.

    Hi, I was working in WORD on a file containing huge data. My machine just hung up one day while working and now I seem to have lost the file how do I get it back.  Please HELP me.

    Well, iCloud has nothing to do with this.
    Do you have the built-in backup function Time Machine running on your Mac?
    See: http://support.apple.com/kb/ht1427

  • I just updated my iPod touch and all my pictures are gone!!! How do I get them back? Please help!!!

    I just updated my iPod touch 4th generation to iOS 6.0.1 and all my pictures are gone!!! Everything else is there but my pictures! How do I get them back? Please help!!!

    If the photos were i your iPod's Camera Roll album (taken by or saved to the iPod you can:
    - If your PhotoStream is on you can get the last 30 days worth back. See that topic here:
    iOS: Importing personal photos and videos from iOS devices to your computer
    - Or you can restore from backup if you backed up when the photos were on the iPod.
    If the photos were synced to the iPod then you have to get them from where you got them the first time.

  • HT1386 I have been trying to sync my iPhone and its not syncing. I've synced it before but now it has gone away. How can I re-sync it? Please help.

    I have been trying to sync my iPhone and its not syncing. I've synced it before but now it has gone away. How can I re-sync it? Please help.

    you did enable Music syncing in iTunes, yes?

  • How do I get PBS again?  Please help!!!

    I was able to get PBS when I first got Apple TV after putting in a code, but my cable company recently changed their channel lineup, and I can no longer get PBS on Apple TV.  I used to get PBS on channel 314 on my TV, but after speaking with my cable company, I now get it on channel 198, but I can't get anything at PBS on Apple TV. All I get when I go there is the "downloading circle" and nothing happens.  The cable company can't help, and I've written to PBS several times with no reply.  I thought maybe I could get a different code and start over, but I don't know how to do that.  Can anyone help, please.  PBS is one
    of the main reasons I bought Apple TV.  Thanks. 

    I don't know who vaszandrew is, but I (diamond2277) wrote How do I get PBS again?  Please help!!! 
    It got printed and I lost my page so I started over again, and the one above with my question showed             (dated May 2, 9:56 am) as if it were an answer to vasndrew.
    After I wrote, it occurred to me that maybe if I disconnect my Apple TV and reconnect it, I will get PBS, and it worked.  Now I don't need an answer.  Thanks to anyone who was going to answer!  I have to remember my usual answer to technical problems, UNPLUG, AND START AGAIN.

Maybe you are looking for

  • Adobe CS 2 and MacBook Pro Compatibility?

    I currently have Adobe Creative Suite 2 that I run on an old PowerBook G4. I'm looking to purchase a MacBook Pro - will I be able to run Adobe CS2 on it?

  • PSE 9 and Windows 7. Keep getting exceptions on several task.

    After installing Win7 Home Edition, PSE9 gets exceptions but after discarding I am able to continue, but it is annoying. Anything that I can do?

  • ATI Radeon X1900XT 512 MB  for mac pro first  gen

    I am looking for a new graphics card for my first generation mac pro desktop (built 2006)  Currently has ATI Radeon X1900XT 512 MB  installed   Any suggestions on where to find one    Alternative may be to get a new machine M Ferro

  • Button Actions in templatepage  and normal pages

    Hi, I am usig ADF components with JDeveloper 11g. I placed the two Command Buttons named BUTTON1 and BUTTON2 in a Template page to perform two differnt actions. I created the page with that template and placed some inputfield components and Command B

  • BI Publisher is not starting

    Hi, I've OBIEE 10g installed. I've made some changes to BI publisher config and trying to restart in from OC4g (Application:xmlpserver). When I tried to stop it, I got a message 'Can't stop cleanly' Then the stop button is disappeared and only @start