3
클라이언트 및 서버 방법을 사용하여 웨이브 파일을 보냅니다.서버에서 보낸 웨이브 파일을 재생하려면 어떻게해야합니까?
받은 파일을 클라이언트에서 어떻게 재생할 수 있습니까? 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
}
}
고객이 무엇인지 명확히 할 수 있습니까? 비슷한 독립 실행 형 Java 프로세스입니까? –
중복 : http://stackoverflow.com/questions/26305/how-can-i-play-sound-in-java – Ascalonian
[이전 SO 질문] (http://stackoverflow.com/questions/26305/how -can-i-play-sound-in-java)는 java에서 사운드 재생을 처리합니다. –