/*
* Copyright 1990-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version
* 2 only, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License version 2 for more details (a copy is
* included at /legal/license.txt).
*
* You should have received a copy of the GNU General Public License
* version 2 along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 or visit www.sun.com if you need additional
* information or have any questions.
*/
package com.sun.mmedia.rtsp;
import java.io.IOException;
import javax.microedition.io.Connector;
import javax.microedition.io.DatagramConnection;
import javax.microedition.io.Datagram;
import com.sun.j2me.log.Logging;
import com.sun.j2me.log.LogChannels;
public class RtpConnection extends RtpConnectionBase {
DatagramConnection dc = null;
public RtpConnection(int local_port) {
super(local_port);
}
public boolean connectionIsAlive() {
return (null != dc);
}
public void startListening() throws IOException {
String url = "datagram://:" + local_port;
dc = (DatagramConnection)Connector.open(url);
if (null != dc) {
start();
} else {
throw new IOException("Connector.open('" + url + "' returned null.");
}
}
public void stopListening() {
try {
dc.close();
} catch (IOException e) {
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_MMAPI,
"IOException in RtpConnection.stopListening(): " + e.getMessage());
}
}
dc = null;
}
public RtpPacket receivePacket() {
try {
Datagram d = dc.newDatagram(MAX_DATAGRAM_SIZE);
dc.receive(d);
RtpPacket pkt = new RtpPacket(d.getData(),d.getLength());
return pkt;
} catch (IOException e) {
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_MMAPI,
"IOException in RtpConnection.receivePacket(): " + e.getMessage());
}
return null;
}
}
}