I am sending a wave file using the client and server method.
How can I play this file on the client after receiving it?
This is the server code used to send the wave file:
import java.lang.*;
import java.io.*;
import java.net.*;
class Server {
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");
while ( true ) {
try {
ServerSocket srvr = new ServerSocket(PORT);
Socket skt = srvr.accept();
FileOutputStream fos = new FileOutputStream(OUTPUTFILENAME);
BufferedOutputStream out = new BufferedOutputStream(fos);
BufferedInputStream in = new BufferedInputStream( skt.getInputStream() );
int i;
while ((i = in.read()) != -1) {
out.write(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");
}
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
System.err.println("Interrupted");
}
}
}
}
Asmaa
source
share