posted 15 years ago
Hi all,
I am running android server application which is listening to port 4444 to retreive the file.I want to receive the file sent from Desktop socket client application. To perform this task I used following code as Android socket server. But execution stops infinitely at the
bos = new BufferedOutputStream(new FileOutputStream("123.txt")); line, Please help me to find out problem.
FTPServer.java is as follows,
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;
import android.util.Log;
public class FTPServer implements Runnable{
ServerSocket server;
Socket connection;
BufferedInputStream bis;
BufferedOutputStream bos;
byte[] receivedData;
int in;
public void run(){
try {
server = new ServerSocket(4444 );
Log.d("TCP..","FTP started...");
try {
while ( true ) {
connection = server.accept();
Log.w( "TCP","S:: receiving file... " );
receivedData = new byte[8192];
Log.d("hello:","databye done");
bis = new BufferedInputStream(connection.getInputStream());
Log.d("hello:","buffer input done");
bos = new BufferedOutputStream(new FileOutputStream("123.txt")); // this line creates the problem
Log.d("hello:","buffer output done");
while ((in = bis.read(receivedData)) != -1){
bos.write(receivedData,0,in);
}
bos.close();
Log.w("TCP","File Received..... " );
}
}
catch (IOException e ) { }
finally {
}
}
catch(Exception e){
}
}
}