私は、クライアントとサーバーの間のオーディオファイル(mp3)転送コードを記述しました。最初のサーバーが開始し、データグラムパケットが受信されるのを待ってから、クライアントはサーバーにUDPデータグラムパケットを送ります。JAVAでUDPを使用したオーディオファイル転送
\サーバー
クライアント\ serverSocket = new DatagramSocket(4000);
int packetsize=1024;
FileOutputStream fos = null;
try {
fos = new FileOutputStream("zz.wav");
BufferedOutputStream bos = new BufferedOutputStream(fos);
double nosofpackets=Math.ceil(((int) (new File("F:\\nirmal\\1.wav")).length())/packetsize);
byte[] mybytearray = new byte[packetsize];
DatagramPacket receivePacket = new DatagramPacket(mybytearray,mybytearray.length);
System.out.println(nosofpackets+" "+mybytearray+" "+ packetsize);
for(double i=0;i<nosofpackets+1;i++)
{
serverSocket.receive(receivePacket);
byte audioData[] = receivePacket.getData();
System.out.println("Packet:"+(i+1));
bos.write(audioData, 0,audioData.length);
}
は
File myFile = new File("F:\\nirmal\\1.wav");
DatagramSocket ds=new DatagramSocket(9000);
DatagramPacket dp;
int packetsize=1024;
double nosofpackets;
noofpackets= =Math.ceil(((int) myFile.length())/packetsize);
BufferedInputStream bis;
bis = new BufferedInputStream(new= FileInputStream(myFile));
for(double i=0;i<nosofpackets+1;i++)
{
byte[] mybytearray = new byte[packetsize];
bis.read(mybytearray, 0, mybytearray.length);
System.out.println("Packet:"+(i+1));
dp=new DatagramPacket(mybytearray,mybytearray.length,InetAddress.getByName("172.17.13.46"),4000);
}
両方のクライアントANSサーバは、サーバがserverSocket.receiveで動けなく実行されている(receivePacket)は、サーバのようなラインは、任意のpackets.Iを受信していません私はどこでミスをしているのか分かりません。
mp3またはwavファイルでテストしましたか? –
バイナリファイルでテストしました。 原点ファイルsha1と運命ファイルを計算して2つのファイルを調べました。 SHA1 ---------------------------------------- ------ ------- ------------ 9574F1AE5946D8E6A86351389445FECF80242C25 aa.hex 9574F1AE5946D8E6A86351389445FECF80242C25 zz.hex あなたは、両方のファイルが同じSHAを持って見ることができるように私は使用して問題はないと思いますwoul mp3またはwavファイル。 – jmarques