0

「ファイルが正常に受信されました」というメッセージが表示されない場合は、助けてください。クライアントからサーバーにファイルを転送している間、ファイルが受信されても​​メッセージは表示されません。

ソケットを使用してクライアントからサーバーにファイルを転送するプログラムであり、インターフェースもJavaスイングを使用して作成されているため、エラーを修正するのを手伝ってください

package Receiver;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
public class Receive extends JFrame {

public Receive() {

super("Packet hiding");
//Svr3.main();
setSize(350, 300);
setDefaultCloseOperation(EXIT_ON_CLOSE);

Container c = getContentPane();
c.setLayout(new FlowLayout());



JButton readyButton = new JButton("Ready");
JButton next = new JButton("Exit");

readyButton.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent ae) {
  try{
  ServerSocket server=new ServerSocket(127);
      Socket clientS=server.accept();
      Scanner read=new Scanner(System.in);
      Scanner scan=new Scanner(clientS.getInputStream());
      PrintWriter out=new PrintWriter(clientS.getOutputStream(),true);
      String idata,odata;
      int bytesRead;
      int current = 0;
      try
      {

        idata=scan.nextLine();
        String inp;
       inp = JOptionPane.showInputDialog(null, "Question: "+idata);

        odata=inp;
        out.println(odata);

         InputStream in = clientS.getInputStream();


    OutputStream output = new FileOutputStream("C:/Users/KRISHNASAI/Documents/NetBeansProjects/Proj1/src/Receiver/Encrypt.zip");

    byte[] buffer = new byte[1024];
    while ((bytesRead = in.read(buffer)) != -1) {
        output.write(buffer, 0, bytesRead);
    }
           JOptionPane.showMessageDialog(null,"File Recieved Sucessfully");

    // Closing the FileOutputStream handle
    output.close();
    scan.close();
            out.close(); 
            clientS.close();
            server.close();

             }
            catch(Exception e)
             {
              }

             System.out.println("conversation ended");


      }
  catch(Exception e)
       {

       }    
   }
   });

next.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
  try{
  Decrypt.main(null);

  System.exit(0);



}
   catch(Exception e)
       {
         }  
     }
     });


        c.add(readyButton);

        c.add(next);  


        }

        public static void main(String args[]) throws Exception{
        Receive s = new Receive();  
        s.setVisible(true);


     }


         }
4

2 に答える 2