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

Document Type
Homework Help
Book Title
Computer Networking: A Top-Down Approach 6th Edition
Authors
James F. Kurose, Keith W. Ross
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
//----------------
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
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
//------------------
//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
}
}//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();
}
}
}
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");
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
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);
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
{

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.