[출처 :http://blog.naver.com/inganyoyo?Redirect=Log&logNo=90072811148]
receive.java
#####################################################################
import java.io.File;import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.net.UnknownHostException;
public class receiver extends Thread {
Socket socket = null
File file = null
FileOutputStream fos = null
InputStream is = null
public receiver() throws UnknownHostException, IOException {
socket = new Socket("127.0.0.1", 8000);
file = new File("./receiver.avi");
fos = new FileOutputStream(file);
is = socket.getInputStream();
}
public static void main(String[] args) throws UnknownHostException,
IOException {
receiver r = new receiver();
int readCount = 0;
byte[] buffer = new byte[4096];
r.start();
while ((readCount = r.is.read(buffer)) > 0) {
r.fos.write(buffer, 0, readCount);
}
System.out.println(");
r.is.close();
r.fos.close();
r.stop()
}
public void run() {
File file = new File("./receiver.avi");
long curr = 0;
long before = 0;
while (true) {
if (file.exists()) {
try {
Thread.sleep(1000);
curr = file.length();
System.out
.println((double) ((((curr - before) / 1024)) / 1024));
before = curr;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
###################################################################
sender.java
#####################################################################
import java.io.File;import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream
import java.net.ServerSocket;
import java.net.Socket;
public class sender {
public static void main(String[] args) throws IOException {
ServerSocket ss = new ServerSocket(8000);
Socket socket = ss.accept();
OutputStream os = socket.getOutputStream();
File file = new File("./sender.avi");
FileInputStream fis = new FileInputStream(file);
int readCount = 0;
byte[] buffer = new byte[4096];
while((readCount = fis.read(buffer))>0){
os.write(buffer, 0, readCount);
}
System.out.println(");
os.close();
fis.close();
}
}
#####################################################################
'Android_Programma' 카테고리의 다른 글
JAVA 에서 PADDING 값을 내가 원하는 값으로... (0) | 2012.10.07 |
---|---|
[ Android ] 블루투스 설정하기 Using bluetooth in Android (0) | 2012.10.01 |
[Android] 캡쳐영상을 소켓으로 보내어 서버 화면에 띄우기 (0) | 2012.09.14 |
[android] 전체 창 크기 구하기 whole screen size (0) | 2012.09.10 |
[android] inflater 사용하기 (0) | 2012.09.09 |