2009-04-20 15 views
3

私は、クライアントとサーバーの方法を使ってwaveファイルを送信します。サーバーから送信されたウェーブファイルを再生するにはどうすればよいですか?

受信したクライアントでこのファイルを再生するにはどうすればよいですか? javax.sound.sampled APIで

import java.lang.*; 
import java.io.*; 
import java.net.*; 

class Server { 
//D:\Documents and Settings\Desktop\gradpro\test1 
    static final String OUTPUTFILENAME = "C:\\Documents and Settings\\Administratore\\Desktop\\gradpro\\test1\\s1.wav"; 
    static final int PORT  = 8811; 

    public static void main(String args[]) { 

     System.out.println("New server running...\n\n"); 

     // Infinite loop, innit 
     while (true) { 

      try { 
       //Create a socket 
       ServerSocket srvr = new ServerSocket(PORT); 
       Socket skt = srvr.accept(); 

       //Create a file output stream, and a buffered input stream 
       FileOutputStream fos = new FileOutputStream(OUTPUTFILENAME); 
       BufferedOutputStream out = new BufferedOutputStream(fos); 
       BufferedInputStream in = new BufferedInputStream(skt.getInputStream()); 

       //Read, and write the file to the socket 
       int i; 
       while ((i = in.read()) != -1) { 
        out.write(i); 
        //System.out.println(i); 
        System.out.println("Receiving data..."); 
       } 
       out.flush(); 
       in.close(); 
       out.close(); 
       skt.close(); 
       srvr.close(); 
       System.out.println("Transfer complete."); 
      } 
      catch(Exception e) { 

       System.out.print("Error! It didn't work! " + e + "\n"); 
      } 

      //Sleep... 
      try { 
       Thread.sleep(1000); 
      } catch (InterruptedException ie) { 
       System.err.println("Interrupted"); 
      } 

     } //end infinite while loop 
    } 



} 
+0

クライアントが何であるかを明確にすることはできますか?それは同様のスタンドアロンのJavaプロセスですか? –

+2

重複:http://stackoverflow.com/questions/26305/how-can-i-play-sound-in-java – Ascalonian

+0

この[前の質問](http://stackoverflow.com/questions/26305/how -can-i-play-sound-in-java)は、javaでのサウンド再生を扱います。 –

答えて

1

ルック:

これは、ウェーブファイルを送信するために使用されるサーバーコードです。

関連する問題