Ask Experts Questions for FREE Help !
Ask
    amirbm1374's Avatar
    amirbm1374 Posts: 1, Reputation: 1
    New Member
     
    #1

    Jun 28, 2014, 06:26 AM
    Convert a simple server client chat to multi client chat in java
    Hi
    I Have a Simple SERVER CLIENT CHAT , I want to Converted it to a Multi CLIENT CHAT in JAVA , Can you Help me ?
    What Features I Should add ?
    This Is My CLIENT JAVA Code :
    Code:
    public class CLIENT {                 
    //*****************************************************************************
    
        public static void main(String args[]) throws IOException, Exception {
            //2 ************************************ CLIENT *******************************************
            //1 IP ADDRESS = InetAddress (Jens)
            InetAddress ip = InetAddress.getLocalHost();//bayad dar 2 "" bashad STRING HOST
            int port = 1240;
            Socket clientNet = new Socket(ip,port);
            //2
            DataInputStream getting = new DataInputStream(clientNet.getInputStream());
            DataOutputStream giving = new DataOutputStream(clientNet.getOutputStream());
            //3
                   
                    ThreadsSend Send = new ThreadsSend(giving);
                    ThreadsRecieve Recieve = new ThreadsRecieve(giving,getting);
                    Send.start();
                    Recieve.start();
                    new ChatJFrame();
            
            //4
            //clientNet.close();
            }
    }
    //*************************************** SEND CLASS ******************************************************
    
    class ThreadsSend extends Thread{
    private DataOutputStream output;
    public ThreadsSend(DataOutputStream outputs) throws Exception{//CONSTRUCTORi az Class ThreadsSend
    output=outputs;
        
    }
        
    @SuppressWarnings("empty-statement")
    public void run(){
        
    
    String action="";
    hi:
    do{
    //Scanner input = new Scanner(ChatJFrame.field.getText());//az System.in nabayad bashad
    //3
        try {
              //input.next();
            //action = input.next();
                KeyEvent key;
               // key = ;
                //ChatJFrame.button.getModel().isPressed()
                //
                boolean b = ChatJFrame.button.getModel().isPressed();
                if(b){
            output.writeUTF(ChatJFrame.field.getText());
                }
    
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }//catch
      }while(true);//while(true)
    }
        
    }
    
    //************************************** RECIEVE CLASS ***************************************************
    
    class ThreadsRecieve extends Thread {
    
        private DataOutputStream output;
        private DataInputStream input;
        public ThreadsRecieve(DataOutputStream outputs , DataInputStream inputs) throws Exception{//CONSTRUCTORi az Class ThreadsSend
        output=outputs;
        input=inputs;    
            }
           
        public void run(){
        String action="";
        do{//3
            try {
            action = input.readUTF();
                if(action.equals("bye")){
                            output.writeUTF("bye");
                System.exit(0);
                
                }
                            ChatJFrame.area.append("Ebi: " + action + "\n");
                          //  System.out.println("Ebi :"+action);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }//catch
          }while(true);//while(true)
        }
    }

Check out some similar questions!

Client server programs in java ? [ 0 Answers ]

I have to make a dictionary in Java language. This dictionary should be executable in client server. And it should supports two languages.and it should be able to Update the words. I don't know how can I make it. Please help me.

Write a JAVA application in a client/server environment. [ 1 Answers ]

Write a JAVA application that allows users to update their personal information in a database in a client/server environment. Windows: Window 1: Window1 should allow the user to select between two options ADD or UPDATE. It should contain two buttons and based on the user selection the user...

Client server program in java [ 1 Answers ]

have a problem about writing client-server program. I want to write two (using TCP and UDP) different client and server programs which are used to transfer an ascii file. Some different information about this project is that the server will wait for client connection and when the client is...


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.