Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Convert a simple server client chat to multi client chat in java (https://www.askmehelpdesk.com/showthread.php?t=795396)

  • Jun 28, 2014, 06:26 AM
    amirbm1374
    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)
        }
    }


  • All times are GMT -7. The time now is 09:42 AM.