Announcement

Collapse
No announcement yet.

[JAVA] Lỗi không không chạy được

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [JAVA] Lỗi không không chạy được

    Hiện tại mình có 2 flie ,Client - kết nối -Server . Nhưng khi run file server.java thì bị lỗi.Nhờ mọi người giúp mình.
    Code:
    import java.io.*;
    import java.net.*;
    
    public class Server {
        public static void main(String[] argv) throws Exception{
            ServerSocket welcomeSocket= new ServerSocket(6789);
            while(true){
                Socket connectSocket = welcomeSocket.accept();
                BufferedReader inFormClient =new BufferedReader(new InputStreamReader(connectSocket.getInputStream()));
                //doc data
               String c = inFormClient.readLine();
               String d = inFormClient.readLine();  
               float a = Float.parseFloat(c);
               float b = Float.parseFloat(d);
               float sum = a+b;
               String result = sum + "\n";
               
           //Gui data ve cho Client
           DataOutputStream outToClient = new DataOutputStream(connectSocket.getOutputStream());
           outToClient.writeBytes(result);
           
        }
        }
    }

    Client.java
    Code:
    import java.io.*;
    import java.net.*;
    
    public class Client {
      
                                         
       
        public static void main(String argv[]) throws Exception{
            String a,b;
            
            Socket clientSocket = new Socket("NguyenNam",8888);
            BufferedReader inFormUse =new BufferedReader(new InputStreamReader(System.in));
                //Nhap data vao
            System.out.println("a = ");
            a=inFormUse.readLine();
            System.out.println("b = ");
            b=inFormUse.readLine();
            
                //
            DataOutputStream outToServer =new DataOutputStream(clientSocket.getOutputStream());
                
                
                //Gui data toi server
            outToServer.writeBytes(a + "" );
            outToServer.writeBytes(b + "");
                //
            BufferedReader inFormServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
                
                //Doc data tu server ve
            String result=inFormServer.readLine();
            System.out.print("CLient");
                
                //Dong ket noi 
            
            clientSocket.close();
        
          
            
        }
                               
    }

LHQC

Collapse
Working...
X