Networking Java Solutions Homework get an Image object from the payload bitstream

subject Type Homework Help
subject Pages 9
subject Words 1319
subject Authors James F. Kurose, Keith W. Ross

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
Solutions for Programming Assignment 7
Below are the solutions for the RTSP/RTP lab. There are two classes: Client,
RTPpacket.
Client.java
import java.io.*;
JButton setupButton = new JButton("Setup");
JButton playButton = new JButton("Play");
JButton pauseButton = new JButton("Pause");
JButton tearButton = new JButton("Teardown");
JPanel mainPanel = new JPanel();
Timer timer; //timer used to receive data from the UDP socket
byte[] buf; //buffer used to store data received from the
server
//RTSP variables
//----------------
page-pf2
server
int RTSPSeqNb = 0; //Sequence number of RTSP messages within
the session
int RTSPid = 0; //ID of the RTSP session (given by the RTSP
Server)
//Frame
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
//Buttons
page-pf3
iconLabel.setIcon(null);
//frame layout
mainPanel.setLayout(null);
mainPanel.add(iconLabel);
mainPanel.add(buttonPanel);
//allocate enough memory for the buffer used to receive data
from the server
buf = new byte[15000];
}
//------------------------------------
//main
//get video filename to request:
VideoFileName = argv[2];
//Establish a TCP connection with the server to exchange
RTSP messages
//------------------
page-pf4
//Handler for buttons
//------------------------------------
//Handler for Setup button
//-----------------------
class setupButtonListener implements ActionListener{
RTPsocket.setSoTimeout(5);
}
catch (SocketException se)
{
System.out.println("Socket exception: "+se);
System.exit(0);
}
//init RTSP sequence number
page-pf5
}
}//else if state != INIT then do nothing
}
}
//Handler for Play button
//-----------------------
class playButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e){
{
//change RTSP state and print out new state
state = PLAYING;
System.out.println("New RTSP state: PLAYING");
//start the timer
timer.start();
}
}
}
page-pf6
send_RTSP_request("PAUSE");
//Wait for the response
if (parse_server_response() != 200)
System.out.println("Invalid Server Response");
else
{
//System.out.println("Teardown Button pressed !");
//increase RTSP sequence number
RTSPSeqNb++;
//Send TEARDOWN message to the server
send_RTSP_request("TEARDOWN");
page-pf7
System.exit(0);
}
}
}
//------------------------------------
//Handler for timer
//------------------------------------
class timerListener implements ActionListener {
//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
page-pf8
payload_length);
//display the image as an ImageIcon object
icon = new ImageIcon(image);
iconLabel.setIcon(icon);
}
catch (InterruptedIOException iioe){
String StatusLine = RTSPBufferedReader.readLine();
//System.out.println("RTSP Client - Received from
Server:");
System.out.println(StatusLine);
StringTokenizer tokens = new StringTokenizer(StatusLine);
page-pf9
tokens = new StringTokenizer(SessionLine);
tokens.nextToken(); //skip over the Session:
RTSPid = Integer.parseInt(tokens.nextToken());
}
}
catch(Exception ex)
{
System.out.println("Exception caught : "+ex);
RTSP/1.0"+CRLF);
//write the CSeq line:
RTSPBufferedWriter.write("CSeq: "+RTSPSeqNb+CRLF);
//check if request_type is equal to "SETUP" and in this
case write the Transport: line advertising to the server the
{
page-pfa

Trusted by Thousands of
Students

Here are what students say about us.

Copyright ©2022 All rights reserved. | CoursePaper is not sponsored or endorsed by any college or university.