Hallo,
ich habe ein Problem, bei dem mir leider keine Lösung einfällt. Google lieferte bis dato auch keine Antworten die mir weiterhelfen konnten. Deshalb versuche ich es hier:
Folgende Konstellation :
1. einen Lauscher (soll Audio Stream empfangen und abspielen)
2. einen Sender (liest das Mikro aus und sendet einen Audio Stream an den Empfänger)
Problem: nach ca. 2-4 Sekunden bricht der Stream einfach ab mit folgender Exception (Sender):
;(java.net.SocketException: Software caused connection abort: socket write error
Die entsprechenden Quellcodeabschnitte sehen wie folgt aus:
Lauscher:
Sender:
Über die Variable talk wollte ich eigentlich den Stream abbrechen, leider bricht er schon vorher ab und ich habe keine Ahnung warum das der Fall sein könnte.
Ich bedank mich schon mal im Voraus für eventuelle Tips oder Hinweise.
LG,
Muli
ich habe ein Problem, bei dem mir leider keine Lösung einfällt. Google lieferte bis dato auch keine Antworten die mir weiterhelfen konnten. Deshalb versuche ich es hier:
Folgende Konstellation :
1. einen Lauscher (soll Audio Stream empfangen und abspielen)
2. einen Sender (liest das Mikro aus und sendet einen Audio Stream an den Empfänger)
Problem: nach ca. 2-4 Sekunden bricht der Stream einfach ab mit folgender Exception (Sender):
;(java.net.SocketException: Software caused connection abort: socket write error
Die entsprechenden Quellcodeabschnitte sehen wie folgt aus:
Lauscher:
Java:
public class Lauscher extends Thread {
int port;
private boolean runs=false;
public Lauscher(int port) {
this.port = port;
}
public void run() {
try {
System.out.println("Starte Voice Server auf : " + port);
ServerSocket srvSock = new ServerSocket(port);
while (true) {
runs=true;
Socket mySock = srvSock.accept();
if (srvSock.isBound())
System.out.println("Connected");
lauscher(mySock);
mySock.close();
}
} catch (Exception e) {
runs=false;
System.out.println("Ferhler Voice Server :" + e);
}
}
public boolean isRunning(){
return runs;
}
private void lauscher(Socket mySock) {
SourceDataLine line = null;
try {
AudioFormat audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100.0F, 6, 2, 4, 44100.0F, false);
byte buf[] = new byte[1024];
DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
line = (SourceDataLine) AudioSystem.getLine(info);
line.open(audioFormat);
int cnt = 0;
while (true) {
DataInputStream in = new DataInputStream(mySock.getInputStream());
in.read(buf, 0, 1024);
if (in.readInt() == 0 | buf.equals(null) | !mySock.isConnected() | mySock.isClosed()) {
System.out.println("no data read");
break;
} else {
line.start();
line.write(buf, 0, 1024);
cnt++;
}
}
line.close();
} catch (Exception e) {
if (line != null) {
line.flush();
line.close();
}
}
}
Sender:
Java:
public class Sender extends Thread {
private boolean talk = false;
private String host;
public Sender(String host) {
this.host = host;
}
public void setHost(String host) {
this.host = host;
}
public void ende() {
talk = false;
}
public void run() {
talk = true;
try {
AudioFormat audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100.0F, 16, 2, 4, 44100.0F, false);
DataLine.Info info = new DataLine.Info(TargetDataLine.class, audioFormat);
TargetDataLine tdl = (TargetDataLine) AudioSystem.getLine(info);
AudioInputStream ais = new AudioInputStream(tdl);
int voice_port =2000;
System.out.println("Verbinde : " + host + ":" + voice_port);
Socket mySock = new Socket(host, voice_port);
DataOutputStream out = new DataOutputStream(mySock.getOutputStream());
tdl.open(audioFormat);
tdl.start();
byte[] buf = new byte[1024];
int cnt = 0;
while (talk) {
int bytesIn = tdl.read(buf, 0, 1024);
out.write(buf, 0, bytesIn);
out.flush();
cnt++;
}
out.write(0);
out.close();
tdl.stop();
tdl.close();
mySock.close();
} catch (LineUnavailableException err) {
System.out.println(err.getMessage());
} catch (IOException e) {
System.out.println(">" + e);
}
}
}
Über die Variable talk wollte ich eigentlich den Stream abbrechen, leider bricht er schon vorher ab und ich habe keine Ahnung warum das der Fall sein könnte.
Ich bedank mich schon mal im Voraus für eventuelle Tips oder Hinweise.
LG,
Muli