Pessoal , peguei este código no site da sun , que serve pra receber pacotes UDP de som, mas dá sempre uma exceção . O código é este :
[code]
// — cut from here… — //
import java.io.;
import java.net.;
import java.util.*;
import javax.media.;
import javax.media.format.;
import javax.media.protocol.;
import javax.media.rtp.;
import javax.media.rtp.event.;
import javax.media.rtp.rtcp.;
public class RTPSocketPlayer implements ControllerListener {
// ENTER THE FOLLOWING SESSION PARAMETERS FOR YOUR RTP SESSION
// RTP Session address, multicast, unicast or broadcast address
String address = “172.30.10.1”;
// RTP Session port
int port = 8000;
// Media Type i.e. one of audio or video
String media = “audio”;
// DO NOT MODIFY ANYTHING BELOW THIS LINE
// The main rtpsocket abstraction which we will create and send
// to the Manager for appropriate handler creation
RTPSocket rtpsocket = null;
// The control RTPPushDataSource of the above RTPSocket
RTPPushDataSource rtcpsource = null;
// The GUI to handle the player
// PlayerWindow playerWindow;
// The handler created for the RTP session,
// as returned by the Manager
Player player;
// maximum size of buffer for UDP receive from the sockets
private int maxsize = 2000;
UDPHandler rtp = null;
UDPHandler rtcp = null;
public RTPSocketPlayer() {
// create the RTPSocket
rtpsocket = new RTPSocket();
// set its content type :
// rtpraw/video for a video session
// rtpraw/audio for an audio session
String content = “rtpraw/” + media;
rtpsocket.setContentType(content);
// set the RTP Session address and port of the RTP data
rtp = new UDPHandler(address, port);
// set the above UDP Handler to be the
// sourcestream of the rtpsocket
rtpsocket.setOutputStream(rtp);
// set the RTP Session address and port of the RTCP data
rtcp = new UDPHandler(address, port +1);
// get a handle over the RTCP Datasource so that we can
// set the sourcestream and deststream of this source
// to the rtcp udp handler we created above.
rtcpsource = rtpsocket.getControlChannel();
// Since we intend to send RTCP packets from the
// network to the session manager and vice-versa, we need
// to set the RTCP UDP handler as both the input and output
// stream of the rtcpsource.
rtcpsource.setOutputStream(rtcp);
rtcpsource.setInputStream(rtcp);
// connect the RTP socket data source before
// creating the player
try {
rtpsocket.connect();
player = Manager.createPlayer(rtpsocket);
// rtpsocket.start();
} catch (NoPlayerException e) {
System.err.println(e.getMessage());
e.printStackTrace();
return;
}
catch (IOException e) {
System.err.println(e.getMessage());
e.printStackTrace();
return;
}
if (player != null) {
player.addControllerListener(this);
// send this player to out playerwindow
// playerWindow = new PlayerWindow(player);
}
}
public synchronized void controllerUpdate(ControllerEvent ce) {
if ((ce instanceof DeallocateEvent) ||
(ce instanceof ControllerErrorEvent)) {
// stop udp handlers
if (rtp != null) rtp.close();
if (rtcp != null) rtcp.close();
}
}
// method used by inner class UDPHandler to open a datagram or
// multicast socket as the case maybe
private DatagramSocket InitSocket(String sockaddress, int sockport)
{
InetAddress addr = null;
DatagramSocket sock = null;
try {
addr = InetAddress.getByName(sockaddress);
if (addr.isMulticastAddress()) {
MulticastSocket msock = new MulticastSocket(sockport);
msock.joinGroup(addr);
sock = (DatagramSocket)msock;
}
else {
sock = new DatagramSocket(sockport,addr);
}
return sock;
}
catch (SocketException e) {
e.printStackTrace();
return null;
}
catch (UnknownHostException e) {
e.printStackTrace();
return null;
}
catch (IOException e) {
e.printStackTrace();
return null;
}
}
// INNER CLASS UDP Handler which will receive UDP RTP Packets and
// stream them to the handler of the sources stream. IN case of
// RTCP, it will also accept RTCP packets and send them on the
// underlying network.
public class UDPHandler extends Thread implements PushSourceStream,
OutputDataStream
{
DatagramSocket mysock;
DatagramPacket dp;
SourceTransferHandler outputHandler;
String myAddress;
int myport;
boolean closed = false;
// in the constructor we open the socket and create the main
// UDPHandler thread.
public UDPHandler(String haddress, int hport) {
myAddress = haddress;
myport = hport;
mysock = InitSocket(myAddress,myport);
setDaemon(true);
start();
}
// the main thread receives RTP data packets from the
// network and transfer’s this data to the output handler of
A