스레드 관련되어서 질문드립니다.... 제발부탁드립니다..

park881221의 이미지

안녕하세요.... 고수님들 제발 도와주세요...ㅠ
자바 서버소켓프로그래밍 질문드립니다....
포트를 두개 열어서....
Android 서버는 android 에서 파일을 받아오고... f1
window 서버는 window 에서 파일을 받아옵니다.. f2
이 두파일을 비교하는 prepare 클래스에서 .. 실행을하는데
f1,f2 를 비교하는 소스좀 부탁드립니다....

소스코드내용
 
import java.io.*;
import java.net.*;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; 
import java.nio.file.Files;
import java.nio.file.Paths; 
 
 
class Server1 {  
 
 
	public static class AndroidServer extends Server1 implements Runnable{
		public static final int serverPort = 10200;
		@Override
		public void run(){
			try{
				System.out.println("----------------------------");
				System.out.println("AndoridServer 동작중입니다...");  
				System.out.println("----------------------------");
 
				while(true)
				{
				ServerSocket serverSocket = new ServerSocket(serverPort);
				Socket sock = serverSocket.accept();
				System.out.println("AndroidClient 접속하였습니다.");
				try{
					BufferedReader in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
					String str = in.readLine();
					System.out.println("수신중인 파일 이름 : " + str);
					File f1 = new File("c:\\Temp", str);
					FileOutputStream output = new FileOutputStream(f1);
					byte[] buf = new byte[1024];
					while(sock.getInputStream().read(buf)>0){
						output.write(buf);
						output.flush();
					}
					in.close();
					output.close();
					System.out.println(str + ".std 수신완료");
					String s1 = readFile(f1.getAbsolutePath(), StandardCharsets.UTF_8);
				}catch(Exception e){
					System.out.println("서버에러");
					e.printStackTrace();
				}finally{
					}
				}
			}catch(IOException e)
				{
					e.printStackTrace();
				}
			}
 
		static String readFile(String path, Charset encoding)throws IOException {     
					byte[] encoded = Files.readAllBytes(Paths.get(path));
					System.out.println("올바른 파일을 선택하여주세요.");
					return encoding.decode(ByteBuffer.wrap(encoded)).toString();
					}
 
 
	public static class WindowServer extends Server1 implements Runnable{
		public static final int serverPort = 5555;
		@Override
		public void run(){
			try{
				System.out.println("----------------------------");
				System.out.println("WindowServer 동작중입니다...");  
				System.out.println("----------------------------");
 
				ServerSocket server = new ServerSocket(serverPort);
				Socket sk = server.accept();
				System.out.println("Window Client 접속하였습니다.");
				try{
					InputStream input = sk.getInputStream();   
					BufferedReader inReader = new BufferedReader
							(new InputStreamReader(sk.getInputStream())); 
					BufferedWriter outReader = new BufferedWriter
							(new OutputStreamWriter(sk.getOutputStream()));
					// Read the filename     
					String filename = inReader.readLine(); 
					System.out.println("수신중인 파일 이름 : " + filename);
					File f3 = new File("C://tmp/", filename);      
					if(!f3.isDirectory()) {       
						f3.mkdir();    
						}  
					FileOutputStream wr = new FileOutputStream(new File("C://tmp/" + filename));
					byte[] buffer = new byte[sk.getReceiveBufferSize()];
					int bytesReceived = 0;           
					while((bytesReceived = input.read(buffer))>0)  
					{            
						// Write to the file 
						wr.write(buffer,0,bytesReceived); 
						}                  
					File f2 = new File("C://tmp/" + filename);  
					String s2 = readFile(f2.getAbsolutePath(), StandardCharsets.UTF_8);
				}catch(Exception e){
			}finally{
				}
			}catch(IOException e){
				e.printStackTrace();
				}
			}
 
 
		static String readFile(String path, Charset encoding)throws IOException {     
					byte[] encoded = Files.readAllBytes(Paths.get(path));
					System.out.println("올바른 파일을 선택하여주세요.");
					return encoding.decode(ByteBuffer.wrap(encoded)).toString();
					}
 
		}
 
	public static class Prepare extends Server1 implements Runnable{
		@Override
		public void run(){
 
			try{
 
			}catch(Exception e){
				e.printStackTrace();
			}
		}
	}
	public static void main(String args[])throws Exception {
		File f1;
		File f2;
 
		Thread as = new Thread(new AndroidServer());
		as.setName("AndroidServer");
		Thread ws = new Thread(new WindowServer());
		ws.setName("WindowServer");
		Thread pp = new Thread(new Prepare());
		pp.setName("Prepare");
		as.start();
		ws.start();
		pp.start();
		}
	}
	}
mirheekl의 이미지

http://stackoverflow.com/questions/5163902/binary-diff-library-for-java

여길 보면 JBDIFF라는게 추천이 되어 있네요.. http://sourceforge.net/p/jbdiff/home/Home/

또는, 서버 플랫폼이 정해져있다면, 그냥 파일 비교를 해주는 외부 프로그램을 실행해도 됩니다. 그정도는 웬만한 OS에는 기본으로 다 들어있으니..
예를 들어 윈도라면 FC /B 명령을 사용하면 바이너리 비교를 할 수 있습니다. 그리고 리턴 코드를 받아오거나 출력을 캡처해서 결과물을 긁어오면 되겠죠.

--

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.