Hi

I am transfering files from PC to J2ME Midlet and from J2ME midlet to pc. I am using socket communication and data streams. Both the desktop application and J2ME midlet are running a server thread which is listening on a port. When any application requests the server thread it recieves filename from the client and then start sending file to it. File is transfered successfully from desktop applicatin to midlet but any of the application i.e; Desktop or j2me client thread requests the j2me server thread it does not receive file. The server thread sends the file completely and give message of completion but client stucks and does not receive not even a single byte.

Code for both the threads is as follows.

This thread listens and after a connection request it creates another thread for sending file.

Code:
public void run(){
    try{
          //ServerSocketConnection server = (ServerSocketConnection)Connector.open("socket://:5000");
            while(true){
              StreamConnection connection=server.acceptAndOpen();
              DataInputStream input=new DataInputStream(connection.openInputStream());
              String filePath=input.readUTF();

              Thread thread = new Thread(new P2PMobSender(filePath,connection));
              thread.start();
            }
        }catch(Exception ex){
            //JOptionPane.showMessageDialog(null,ex.getMessage());
            Alert alert=new Alert("Exception:",ex.getMessage(),null,AlertType.ERROR);
            alert.setTimeout(Alert.FOREVER);
            Display.getDisplay(P2PMidlet.instance).setCurrent(alert);

        }

  }
This is the FielSender thread that acutally sends file.
Code:
public void run() {
    try {
      byte[] b=new byte[1024];
      DataOutputStream output = new DataOutputStream(connection.openOutputStream());

      FileConnection file=(FileConnection)Connector.open(filePath);
      DataInputStream inputFile=new DataInputStream(file.openInputStream());
      int i=0;
      while((i=inputFile.read(b))!=-1){
        output.write(b,0,i);
        output.flush();
      }
      inputFile.close();
      output.close();

      Alert alert=new Alert("Sending:","Sendig complete.",null,AlertType.ALARM);
      alert.setTimeout(Alert.FOREVER);
      Display.getDisplay(P2PMidlet.instance).setCurrent(alert);

    }
    catch (IOException ex) {
      Alert alert=new Alert("Client:Exception:",ex.getMessage(),null,AlertType.ALARM);
      alert.setTimeout(Alert.FOREVER);
      Display.getDisplay(P2PMidlet.instance).setCurrent(alert);

    }
  }
This is the client thread that recives file.

Code:
public void run(){
    try {
      //SocketConnection scon = (SocketConnection) Connector.open("socket://localhost:5000");

      StreamConnection scon=(StreamConnection)Connector.open("socket://localhost:5000");


      DataOutputStream output=new DataOutputStream(scon.openDataOutputStream());
      DataInputStream input=new DataInputStream(scon.openDataInputStream());

      FileConnection file=(FileConnection)Connector.open("file:///c:/data/Images/Downloaded.txt");//+fileName);

      if(!file.exists()){
        file.create();
      }
      DataOutputStream fileOutput=new DataOutputStream(file.openDataOutputStream());

      output.writeUTF(fileName);
      output.flush();
      byte[] b=new byte[1024];
      int i=0;
      while((i=input.read(b))!=-1){
        fileOutput.write(b,0,i);
        fileOutput.flush();
      }
      fileOutput.close();
      input.close();
      output.close();

      Alert alert=new Alert("Downoad","\""+fileName+"\" downloaded successfully.",null,AlertType.INFO);
      alert.setTimeout(5000);
      Display.getDisplay(P2PMidlet.instance).setCurrent(alert);

    }
    catch (Exception ex) {
      Alert alert=new Alert("Server:Exception:",ex.getMessage(),null,AlertType.ALARM);
      alert.setTimeout(Alert.FOREVER);
      Display.getDisplay(P2PMidlet.instance).setCurrent(alert);
    }
  }

If please someone can help me I shal be thankfull.