class timerListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
//Construct a DatagramPacket to receive data from the UDP socket
rcvdp = new DatagramPacket(buf, buf.length);
try{
//receive the DP from the socket:
RTPsocket.receive(rcvdp);
//create an RTPpacket object from the DP
RTPpacket rtp_packet = new RTPpacket(rcvdp.getData(), rcvdp.getLength());
/*Fix for funky server!!!
* only process packets that are in order
*
*/
//increment packet count
if(rtp_packet.getsequencenumber() > prev_seqnb) {
prev_seqnb = rtp_packet.getsequencenumber();
//print important header fields of the RTP packet received:
System.out.println("Got RTP packet with SeqNum # "+rtp_packet.getsequencenumber()+" TimeStamp "+rtp_packet.gettimestamp()+" ms, of type "+rtp_packet.getpayloadtype());
//print header bitstream:
rtp_packet.printheader();
//get the payload bitstream from the RTPpacket object
int payload_length = rtp_packet.getpayload_length();
byte [] payload = new byte[payload_length];
rtp_packet.getpayload(payload);
//get an Image object from the payload bitstream
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image image = toolkit.createImage(payload, 0, payload_length);
//display the image as an ImageIcon object
icon = new ImageIcon(image);
iconLabel.setIcon(icon);
}
else
System.out.println("\n***Packet with SeqNum#: "+rtp_packet.getsequencenumber() +" dropped!***\n");
}
catch (InterruptedIOException iioe){
//System.out.println("Nothing to read");
}
catch (IOException ioe) {
System.out.println("Exception caught(timer): "+ioe);
}
}
}