Permalink
Browse files

Fixed a bug in the binary. RTSPResponder is now a thread

  • Loading branch information...
1 parent 43c525f commit 35bd02d3a8a0f43a5c9bd90649ac75c90400bb5f @bencall committed May 5, 2011
Showing with 51 additions and 36 deletions.
  1. +2 −1 .gitignore
  2. +1 −2 src/AudioServer.java
  3. +8 −5 src/LaunchThread.java
  4. +33 −24 src/RTSPResponder.java
  5. +0 −1 src/Window.java
  6. +7 −3 src/ZeroConfEmitter.java
View
@@ -12,4 +12,5 @@
/.classpath
/bin/.DS_Store
/libs/.DS_Store
-/src/.DS_Store
+/src/.DS_Store
+/.DS_Store
View
@@ -22,7 +22,7 @@
// Sockets
private DatagramSocket sock, csock;
- private UDPListener l1, l2;
+ private UDPListener l1;
// client address
private InetAddress rtpClient;
@@ -92,7 +92,6 @@ private void initRTP(){
}
l1 = new UDPListener(sock, this);
- //l2 = new UDPListener(csock, this);
}
/**
View
@@ -6,17 +6,20 @@
/**
- * Main class
+ * LaunchThread class which starts services
* @author bencall
*
*/
-
-//
public class LaunchThread extends Thread{
private RTSPResponder repondeur;
private BonjourEmitter emetteur;
private String name;
+ ZeroConfEmitter emetteur1;
+ /**
+ * Constructor
+ * @param name
+ */
public LaunchThread(String name){
super();
this.name = name;
@@ -48,7 +51,7 @@ public void run(){
// DNS Emitter (Bonjour)
repondeur = new RTSPResponder(port, hwAddr);
emetteur = new BonjourEmitter(name, sb.toString(), repondeur.getPort());
- //emetteur1 = new ZeroConfEmitter(nameField.getText(), sb.toString(), repondeur.getPort());
+ //emetteur1 = new ZeroConfEmitter(name, sb.toString(), repondeur.getPort());
repondeur.start();
@@ -60,10 +63,10 @@ public void run(){
public synchronized void stopThread(){
emetteur.stop();
+ //emetteur1.stop();
try {
repondeur.stopThread();
} catch (IOException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
}
View
@@ -8,6 +8,7 @@
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
+import java.net.SocketException;
import java.security.KeyPair;
import java.security.Security;
import java.util.regex.Matcher;
@@ -95,6 +96,7 @@ public int getPort(){
}
public void handlePacket(RTSPPacket packet){
+
// We init the response holder
StringBuilder response = new StringBuilder("RTSP/1.0 200 OK\r\n");
response.append("Audio-Jack-Status: connected; type=analog\r\n");
@@ -235,6 +237,9 @@ public void handlePacket(RTSPPacket packet){
// We close the response
response.append("\r\n");
+ System.out.println(packet.getRawPacket());
+ System.out.println(response.toString());
+
// Write the packet to the wire
BufferedWriter oStream;
try {
@@ -310,39 +315,43 @@ public void handlePacket(RTSPPacket packet){
*/
public void run() {
boolean fin = stopThread;
- BufferedReader in;
try {
// Socket & Streams
// Socket init
- if(socket == null){
+ if(socket == null && !stopThread){
socket = sock.accept();
}
- in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- String packet = "";
- while(!fin){
- // Buffer
- char[] buffer = new char[4096];
- in.read(buffer);
- String temp = new String(buffer);
- packet = packet + temp;
-
- // If packet completed
- Pattern p = Pattern.compile("(.*)\r\n\r\n");
- Matcher m = p.matcher(packet);
- if(m.find()){
- //System.out.println(packet);
- // We handle the packet
- RTSPPacket paquet = new RTSPPacket(packet);
- this.handlePacket(paquet);
- packet = "";
- break;
- }
+ if(socket != null){
+ BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- synchronized(this){
- fin = stopThread;
+ String packet = "";
+ while(!fin){
+ // Buffer
+ char[] buffer = new char[4096];
+ in.read(buffer);
+ String temp = new String(buffer);
+ packet = packet + temp;
+
+ // If packet completed
+ Pattern p = Pattern.compile("(.*)\r\n\r\n");
+ Matcher m = p.matcher(packet);
+ if(m.find()){
+ //System.out.println(packet);
+ // We handle the packet
+ RTSPPacket paquet = new RTSPPacket(packet);
+ this.handlePacket(paquet);
+ packet = "";
+ break;
+ }
+
+ synchronized(this){
+ fin = stopThread;
+ }
}
+ in.close();
+ socket.close();
}
} catch (IOException e) {
e.printStackTrace();
View
@@ -1,7 +1,6 @@
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
View
@@ -2,7 +2,6 @@
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Hashtable;
-import java.util.Map;
import javax.jmdns.JmDNS;
import javax.jmdns.JmmDNS;
@@ -22,7 +21,6 @@
private static JmmDNS dns;
public ZeroConfEmitter(String name, String identifier, int port) throws UnknownHostException, IOException, InterruptedException{
-
// Announce Raop Service
Hashtable<String, String> props = new Hashtable<String, String>();
props.put("txtvers", "1");
@@ -38,10 +36,16 @@ public ZeroConfEmitter(String name, String identifier, int port) throws UnknownH
props.put("cn", "0,1");
props.put("vn", "3");
- ServiceInfo info = ServiceInfo.create("._raop._tcp", identifier+"@"+name, port, "dfjgjgghhfh");
+ //ServiceInfo info = ServiceInfo.create("._raop._tcp", identifier+"@"+name, port, "dfjgjgghhfh");
+ //info.setText(props);
+
+
+ // Announce Raop Service
+ ServiceInfo info = ServiceInfo.create(identifier+"@"+name + "._raop._tcp.local", identifier+"@"+name, port, "tp=UDP sm=false sv=false ek=1 et=0,1 cn=0,1 ch=2 ss=16 sr=44100 pw=false vn=3 txtvers=1");
info.setText(props);
dns = JmmDNS.Factory.getInstance();
+ ((JmmDNSImpl)dns).inetAddressAdded(new NetworkTopologyEventImpl(JmDNS.create(InetAddress.getByName("localhost")), InetAddress.getByName("localhost")));
dns.registerService(info);
System.out.println("Service registered");

0 comments on commit 35bd02d

Please sign in to comment.