Methods Summary |
---|
public void | cleanup()
Debug.println("RTSP::Connection:cleanup, id=" + connectionId);
close();
rtspManager.removeConnection(connectionId);
|
public void | close()
connectionIsAlive = false;
try {
if (socket != null) {
// System.out.println( "close socket");
socket.close();
socket = null;
}
} catch (IOException e) {
e.printStackTrace();
}
|
private boolean | eomReached(byte[] buffer)
boolean endReached = false;
int size = buffer.length;
if (size >= 4) {
if (buffer[size - 4] == '\r" && buffer[size - 3] == '\n" &&
buffer[size - 2] == '\r" && buffer[size - 1] == '\n") {
endReached = true;
}
}
return endReached;
|
private int | getContentLength(java.lang.String msg_header)
int length;
int start = msg_header.indexOf("Content-length");
if (start == -1) {
// fix for QTSS:
start = msg_header.indexOf("Content-Length");
}
if (start == -1) {
length = 0;
} else {
start = msg_header.indexOf(':", start) + 2;
int end = msg_header.indexOf('\r", start);
String length_str = msg_header.substring(start, end);
length = new Integer(length_str).intValue();
}
return length;
|
public java.lang.String | getIpAddress()
return socket.getInetAddress().getHostAddress();
|
public void | run()
// System.out.println( "Connection-" + connectionId + " running...");
connectionIsAlive = true;
while (connectionIsAlive) {
try {
InputStream in = socket.getInputStream();
DataInputStream din = new DataInputStream(in);
byte ch = din.readByte();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// read message header:
baos.write(ch);
while (!eomReached(baos.toByteArray())) {
baos.write(din.readByte());
}
// read message body:
int length = getContentLength(new String(baos.toByteArray()));
for (int i = 0; i < length; i++) {
baos.write(din.readByte());
}
if (mp == null) {
mp = new MessageProcessor(connectionId, rtspManager);
}
mp.processMessage(baos.toByteArray());
}
catch (Exception e) {
// System.out.println( "RTSP Connection terminated");
connectionIsAlive = false;
}
}
|
public boolean | sendData(byte[] message)
boolean success = false;
try {
OutputStream out = socket.getOutputStream();
out.write(message);
out.flush();
success = true;
} catch (IOException e) {
// e.printStackTrace();
}
return success;
|