Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 49

ANGLIA RUSKIN UNIVERSITY

Implementing RTP and RTSP protocol For Video Streaming In JAVA Based Chat Application

Contents
1. Introduction ........................................................................................................................................... 5 1.1. 1.2. 1.3. 1.4. 1.5. 2. Media Streaming ........................................................................................................................... 6 Motivation and Problem Statement............................................................................................... 6 Case Study .................................................................................................................................... 7 Project Scope ................................................................................................................................ 8 Project Objectives ......................................................................................................................... 8

Literature Review.................................................................................................................................. 9 2.1. 2.2. File Formats .................................................................................................................................. 9 Streaming Methods ....................................................................................................................... 9 Downloading ......................................................................................................................... 9 Progressive Downloading ................................................................................................... 10 Streaming Servers ............................................................................................................... 10

2.2.1. 2.2.2. 2.2.3. 2.3.

Streaming Video Servers ............................................................................................................ 12 RTP Protocol ....................................................................................................................... 12 Real Time Protocol ............................................................................................................. 14

2.3.1. 2.3.2. 3. 4. 5.

Methodology ....................................................................................................................................... 15 Implementation ................................................................................................................................... 17 References ........................................................................................................................................... 19

Appendix ..................................................................................................................................................... 21

Page 2

Page 3

Table Of Figures
Figure 1: RTSP protocol Over UDP Stream. .................................Error! Bookmark not defined. Figure 2: RTSP over RTP transport Protocol ................................................................................. 8 Figure 3: Live Streaming Server ................................................................................................... 10 Figure 4: Video On Demand Streaming Server ............................................................................ 11 Figure 5: RTSP Communication States ........................................................................................ 13 Figure 6: Chat Page ....................................................................................................................... 17

Page 4

1. Introduction
Media streaming is a multimedia that is sent over a network and played as it is being received by end user (Amir, 2011). Users do not need to wait to download all the media before playback but instead they can play it simultaneously while the media is delivered by the provider. Video-overIP applications have recently attracted a large number of users on the Internet. Traditional clientserver based video streaming solutions incur expensive bandwidth provision cost on the server (Wu and Li, 2011). Therefore there is a need to constantly research into these platforms in order to provide a cost effective and efficient means of sharing video. With the explosive growth of video applications over the Internet, many approaches have been proposed to stream video effectively over packet switched best-effort networks. A number of these use techniques from source and channel coding, or implement transport protocols, or modify system architectures in order to deal with delay, loss, and time-varying nature of the Internet (Nguyen, 2012). Video streaming over best-effort, packet-switched networks is challenging due to a number of factors such as high bit rates, delay, and loss sensitivity. As such, transport protocols such as TCP are not suitable for streaming applications. Conventionally, multimedia streaming applications in the Internet run over UDP instead of TCP due to the following reasons (Jinyao, Wolfgang and Bernhard, 2010). TCP uses the Additive increase multiplicative decrease (AIMD) algorithm for congestion control. This algorithm leads to a varying throughput of real time video stream and hence severely impacts the video quality. TCP applies packet retransmission to guarantee the delivery of packets. But ultimately, such packets may arrive too late for playback and therefore be useless. . To this end, many solutions have been proposed from different perspectives. From source coding perspective, layered and error-resilient video codecs have been proposed.

Page 5

1.1.

Media Streaming

Traditional client-server based video streaming solutions incur expensive bandwidth provision cost on the server and therefore these models are not optimized for real time online video streaming services. The client server model is not highly scalable and is prone to a single point of failure problem. Providing a scalable streaming service, which is resistant and resilient to failure, is very expensive in terms of bandwidth, therefore traditionally most streaming services are delivered through distributed servers content delivery network (CDN) or P2P networks.

This trend has been reversing for over 2 years because the web speed is increasing exponentially. With the imminent worldwide deployment of 4G broadband internet services bandwidth constraint might be totally alleviated. Peer-to-Peer (P2P) networking is a time tested paradigm to build distributed network applications. Recently, several P2P streaming systems (e.g. Sopcast, P2PStream) have been deployed to provide live and on-demand video streaming services on the Internet at low server cost. In Live Media Streaming, the streams are only available at one particular time; while in video on demand (VoD) streams, the streams are stored on a server and are available to be transmitted at a user's request. It provides a large subset of VCR functionality, e.g., pause, fast forward, fast rewind (Amir, 2011).

1.2.

Motivation and Problem Statement

Video streaming is set to experience explosive growth in the coming years. According to Cisco VNI report (2011) by 2012 Internet video will account for over 50 percent of consumer Internet traffic and this will increase to 62% by 2015; the various forms of video the internet now carries TV, VoD, Internet Video, and P2P will account for 91 per cent of consumer traffic.

Page 6

Streaming video has overtaken the popularity of P2P networks because as web speed is increasing, so will the amount of streaming. Rather than concentrate on P2P file sharing, the video service that will be developed in this project will be an Internet video streaming service. This project provides an excellent opportunity to research into how video is being deployed over the internet as a web application.

1.3.

Case Study

The project to be designed is a java based chat server. Although a lot of java based cha server has been built, none is available that is capable of streaming live video using RTP and RTSP protocol. This is mainly due to copyright protection laws; therefore the project will be for purely academic and experimental purposes rather than commercial value. There are various ways by which video can be streamed online but this thesis will focus on the use of the Java RTP and RTSP protocol available in recent releases of java suite.

Page 7

Figure 1: RTSP over RTP transport Protocol

1.4.

Project Scope

There are two main methods of streaming video: Streaming Server and HTTP Streaming. This project is a web based video streaming service based on a streaming server implementing RTP protocol so the end user can start watching the file almost as soon as it begins downloading and therefore be used to broadcast live events or used to share recorded video at. Other forms of video streaming like P2P, progressive downloading will not be implemented but will be discussed.

1.5.

Project Objectives

The objectives of this thesis are listed below To create a social networking tool that people can use to share memorable fun time between themselves. Build a java based chat server that can be supported on different operating system. Build a Video streaming server into the chat application. The chat server will also have file sharing features.

Page 8

2. Literature Review
As discussed in Section 1 above, there are two main methods of deploying video to viewers over the internet. These methods are Download and video streaming. This section covers the different types of video streaming on the internet with particular emphasis Streaming servers and HTTP streaming. The main focus will be on the architecture of these methods and how they affect the efficiency and quality of deployment in different operating systems. Two things are of utmost importance when creating a streaming service and these are the video file format and the streaming method. This is video players generally do not play all available formats. It is therefore necessary to sometimes include multiple players or multiple file formats based on user preference.

2.1.

File Formats

There are many video file formats to choose from when creating video streams. A wide range of video formats, use different codecs to encode and compress video data and they also have their own file formats with different extensions like .swf, .wmv, .mp3, and .mp4. The MP4 format is the most widely used format on internet video because it is supported by YouTube, Flash players and HTML5 (w3schools, 2012). In order to reach the widest audience, it is sometimes imperative to create separate files for the different formats. But this is not practically feasible

2.2.

Streaming Methods

There are two ways to view media on the internet (such as video, audio, animations, etc): Downloading and streaming. 2.2.1. Downloading Media downloading is a form of file access which has some pros and cons. When a file is downloaded, the entire file is saved on the computer before a user can have access and view the files. Video files accessed this way has the advantage that a user can have such as quicker access to different parts of the file; the big disadvantage is that user have to wait for the whole file to downloaded before any of it can be viewed. For small files, this might constitute a small inconvenience but if the files are large, the delay is unacceptable. The easiest way to provide downloadable video files is to use a simple hyperlink to the file. A slightly more advanced method is to embed the file in a web page using special HTML code.

Page 9

2.2.2. Progressive Downloading Progressive downloading or pseudo streaming is another common delivery method on the internet for multimedia objects. It has the same nature of downloading, but provides an option on the client side to play the object while it is being downloaded rather than wait for the whole video file to download. Most media players, such as Windows Media Player and Real Player, support the pseudo streaming mechanism (Lei et al, 2005). A major limit of pseudo streaming appears when the downloading connection is slow and cannot catch up with the playback speed. Users cannot jump forward in the stream since the file is downloaded in sequence. This method therefore simulates true streaming, but doesn't have all the advantages because the client cannot control where and what to watch in the stream. 2.2.3. Streaming Servers Streaming media works differently from downloading method since the client can start viewing or watching the file as soon as it begins downloading (Lei et al, 2005; Silverstone and Fourmaux 2007; Amir, 2011). In effect, the file is sent to the user in a more or less constant stream, and the user watches it as it arrives. The obvious advantage with this method is that no waiting is involved. Streaming media has additional advantages such as being able to broadcast live events sometimes referred to as a webcast or netcast. True streaming video are delivered from a specialized streaming server. Various researches has proven and developed streaming as the most efficient method for delivery multimedia over the internet (Lei et al, 2005).

Figure 2: Live Streaming Server1

Image Available at: http://www.bogotobogo.com/VideoStreaming/videostreaming_etc.php

Page 10

With streaming, the playback of a media object can start shortly after the client receives the initial portion of the object from the streaming server. In addition, streaming provides clients with a variety of controls during playback, such as pause, rewind, jump, etc. This allows a client to start or stop the media stream easily at any time. Compared with downloading and pseudo streaming, the amount of data transferred in streaming is closest to what the client really needs. Because of its many advantages, streaming is used in various Internet applications today.

Figure 3: Video On Demand Streaming Server2 There have been many different researches into multimedia streaming. While Chesire et al (2001) measured the streaming media workload in a windows 2000 environment; Almeida et al (2001) analyzed the workload on the server in an educational environment. A more recent research by Fernandez et al (2011), focused on creating an adaptive and predictive architecture for streaming server with the aim of enhancing the overall video quality especially in environment with low internet bandwidth; by formulating a combination of innovative congestion control-aware mechanisms and filtering technique

Image culled from: http://www.bogotobogo.com/VideoStreaming/videostreaming_etc.php

Page 11

2.3.

Streaming Video Servers

A streaming media or streaming video server is a specialized application which runs on an Internet server. This is often referred to as "true streaming", since other methods only simulate streaming. True streaming has advantages such as:

The ability to handle much larger traffic loads. The ability to detect users' connection speeds and supply appropriate files automatically. The ability to broadcast live events.

There are two ways to have access to a streaming server: 1. Operate you own server (by purchasing or leasing) 2. Sign up for a hosted streaming plan with an ISP (Internet Service Provider) Streaming video servers operate with the Real Time Streaming Protocol to deliver a constant video stream. This protocol is employed in this thesis and is described in details below. 2.3.1. RTP Protocol The Real-Time Streaming Protocol (RTSP) is an application layer protocol that is used for the setup and control of the either a single or several time-synchronized streams of continuous media with real time properties. The protocol is used for establishing and controlling media sessions between end points. It is optimized for live data streams or stored clips which require on demand and/or real time delivery. It should be noted that RTSP does not typically deliver the continuous streams itself, but rather defines a medium of set of control for multiple data delivery and sessions; it provide a means for choosing the delivery channel which can be either TCP or UDP (multicast, unicast or broadcast) and also define the Real Time Protocol Delivery mechanism (Schulzrine et al, 2011). RTSP therefore serves as a control protocol, and as a jumping off point for negotiating transports and negotiating codecs off of servers in a file format independent way.

Page 12

Figure 4: RTSP Communication States3 An RTSP session can use multiple transport-level connection such as a TCP connection. During an RTSP session, a client may open and close multiple reliable transport layer connections to the server when issuing RTSP requests. Alternatively, it may use a connectionless transport protocol such as UDP (Vasquez-Brisneo and Vincent, 2007; rstp.org, 2007). The RTSP server in our architecture is written in Java using jdk1.6.0_25 distribution. It implements the basic RTSP mechanisms to control the streamed data, but once the session is established, media streams are sent using RTP over UDP as the transport mechanism as shown in the diagram below. Java's sophisticated memory management, native support

for threading and concurrency, type safety, made it the program of choice to implement the server. UDP datagram sockets are established on port 25000. More intricate details and description are expostulated in Section 3 and Section 4. The streams created and instantiated by RTSP may use RTP, but the operation of RTSP does not depend on the transport mechanism used to transport the multimedia file. RTSP is intentionally similar in syntax and operation to HTTP/1.1 so that extension mechanisms to HTTP can in most cases also be added to RTSP. However the differences between HTTP/1.1 and RTSP are expounded below:

Available at: http://www.w3.org/2008/WebVideo/Fragments/wiki/UA_Server_RTSP_Communication

Page 13

The protocol identifier in RTSP is different from that of HTTP/1.1. HTTP is stateless in nature while an RSTP server is a stateful server by default; although, this can be turned to

RSTP requests can be initiated by both client and server nodes. Different protocols can be used to carry data in an RSTP connection. RTSP is defined to use ISO 10646 (UTF-8) rather than ISO 8859-1, consistent with current HTML internationalization efforts.

The RTSP Request-URI always contains the absolute URI which is made up of path and host name bundled together in a header field. HTTP/1.1 on the other hand carries only the absolute path in the request and puts the host name in a separate header field because of backward compatibility with a historical blunder.

The protocol supports the following operations:

Retrieval of media from media server: The client can request a presentation description via HTTP or some other method.

Invitation of a media server to a conference: A media server can be "invited" to join an existing conference, either to play back media into the presentation or to record all or a subset of the media in a presentation.

Addition of media to an existing presentation: Particularly for live presentations, it is useful if the server can tell the client about additional media becoming available.

2.3.2. Real Time Protocol The real-time transport protocol (RTP) provides end-to-end delivery services for data with realtime characteristics, such as interactive audio and video or simulation data, over multicast or unicast network services. Applications typically run RTP on top of UDP to make use of its multiplexing and checksum services; both protocols contribute parts of the transport protocol functionality. However, RTP may be used with other suitable underlying network or transport

Page 14

protocols. RTP supports data transfer to multiple destinations using multicast distribution if provided by the underlying network. RTP itself does not provide any mechanism to ensure timely delivery or provide other quality-ofservice guarantees, but relies on lower-layer services to do so. It does not guarantee delivery or prevent out-of-order delivery, nor does it assume that the underlying network is reliable and delivers packets in sequence. The sequence numbers included in RTP allow the receiver to reconstruct the sender's packet sequence, but sequence numbers might also be used to determine the proper location of a packet, for example in video decoding, without necessarily decoding packets in sequence. RTP consists of two closely-linked parts:

The real-time transport protocol (RTP), to carry data that has real-time properties. The RTP control protocol (RTCP), to monitor the quality of service and to convey information about the participants in an on-going session. The latter aspect of RTCP may be sufficient for "loosely controlled" sessions, i.e., where there is no explicit membership control and set-up, but it is not necessarily intended to support all of an application's control communication requirements.

3. Methodology

Page 15

Page 16

4. Implementation

Figure 5: Chat Page

Page 17

Sign-Up Page

Page 18

5. References
Jinyao, Y., Wolfgang, M., Bernhard, P. 2012. Analytical Framework for Streaming over TCP. [ONLINE] Available at: http://people.ee.ethz.ch/~wmuehlba/new2an-2011.pdf. [Accessed 03 February 2012]. X. Hei, C. Liang, J. Liang, Y. Liu, and K. W. Ross. A Measurement Study of a Large-Scale P2P IPTV System. IEEE Transactions on Multimedia, 2007. Wu, C. and Li, B. (2011) Diagnosing Network-wide P2P Live Streaming Inefficiencies. ACM Transactions on Multimedia Computing, Communications and Applications,, 5 (2), p.1-21. L, C. and G, Y. (2012) A survey on peer-to-peer video streaming systems. PEER-TO-PEER NETWORKING AND APPLICATIONS, 1 (1), p.18-28. Nguyen, N. (2012) DISTRIBUTED VIDEO STREAMING OVER INTERNET. Ph,D. University Of California, Berkeley, USA. Amir , P. (2011) P2P Media Streamin. [online] Available at: http://www.sics.se/~amir/files/ download /p2p/p2p_media_streaming_2011.pdf [Accessed: 4th February 2012]. Cisco Incorporated (2012) Cisco Visual Networking Index: Forecast and Methodology, 2010 2015. [online] Available at: http://www.cisco.com/en/US/solutions/collateral/ns341/ns525/ns537 /ns705/ns827/white_paper_c11-481360.pdf [Accessed: 5th February 2012]. 3schools.com (2012) HTML Multimedia . [online] Available at: http://www.w3schools.com/ html/ html_media.asp [Accessed: 22 Feb 2012]. SIGMETRICS Perform. Eval. Rev., Vol. 36 (June 2008), pp. 313-324, doi:10.1145/1384529.1375493 Silverston, T., Fourmaux. O. Measuring P2P IPTV Systems. In Proceedings of the 17th International workshop on Network and Operating Systems Support for Digital Audio & Video, 2007.

Page 19

Lei, G., Songqing, C., Zhen, X., Xiaodong, Z. (2005). Analysis of Multimedia Workloads with Implications for Internet Streaming. In: International World Wide Web Conference Committee (IW3C2), May 10-14, Chiba, Japan. pp.24-34. M. Chesire, A. Wolman, G. Voelker, and H. Levy. Measurement and analysis of a streaming media workload. In Proc. of the 3rd USENIX Symposium on Internet Technologies and Systems, March 2001. J. M. Almeida, J. Krueger, D. L. Eager, and M. K. Vernon. Analysis of educational media server workloads. In Proc. of ACM Workshop on Network and Operating System Support for Digital Audio and Video (NOSSDAV), June 2001. Michaelhanley.ie (2002) RTSP | E-Learning Curve Blog. [online] Available at: http://michaelhanley .ie/elearningcurve/tag/rtsp/ [Accessed: 17 Mar 2012]. H. Schulzrinne (Oct 08 2011). 2326. Real Time Streaming Protocol 2.0 (RTSP). USA: IETF. Developer.apple.com (1997) Developer - QuickTime - Letters from the Ice Floe. [online] Available at: https://developer.apple.com/quicktime/icefloe/dispatch028.html [Accessed: 19 Mar 2012]. Vazquez-Briseno , M. and Vincent , P. (2007) IJCSNS International Journal of Computer Science and Network Security, September 2007. An Adaptable Architecture for Mobile Streaming Applications, 7 (9), p.32-38. rtsp.org (2007) Internet Archive Wayback Machine. [online] Available at: http://www.rtsp.org/ [Accessed: 19 Mar 2012]. W3.org (2012) UA Server RTSP Communication - Media Fragments Working Group Wiki. [online] Available at: http://www.w3.org/2008/WebVideo/Fragments/wiki/UA_Server_RTSP_Communication [Accessed: 19 Mar 2012].

Page 20

Appendix
package javachat;

import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.lang.String; import javax.swing.*;

import java.sql.*; public class FriendList extends JFrame implements ActionListener {

Page 21

private Connection conn = null; private Statement st = null; private ResultSet resultSet = null; int n=7; String friends; String typed;

public FriendList() {

initComponents(); connect(); }

public void connect() { try { String userName = "root"; String password = "redhot"; String url = "jdbc:mysql://localhost/sleeky"; Class.forName ("com.mysql.jdbc.Driver").newInstance(); conn = DriverManager.getConnection (url, userName, password); System.out.println ("Database connection established"); }

Page 22

catch (Exception e) { System.err.println ("Cannot connect to database server"); } read_freind(); }

public void read_freind() { try { st = conn.createStatement(); st.executeQuery("select * from sleeky.fahad1"); resultSet = st.getResultSet();

while (resultSet.next ()) { friends = new String(resultSet.getString("Friend")); jTextArea2.append(friends+"\n\n"); }

} catch(SQLException e) { e.printStackTrace();

Page 23

} }

@SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() {

canvas1 = new java.awt.Canvas(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); jScrollPane2 = new javax.swing.JScrollPane(); jTextArea2 = new javax.swing.JTextArea(); jTextField1 = new javax.swing.JTextField(); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenuItem1 = new javax.swing.JMenuItem(); jMenu4 = new javax.swing.JMenu(); jMenu2 = new javax.swing.JMenu(); jMenuItem2 = new javax.swing.JMenuItem(); jMenuItem3 = new javax.swing.JMenuItem(); jMenuItem4 = new javax.swing.JMenuItem();

Page 24

jMenu3 = new javax.swing.JMenu(); jMenuItem5 = new javax.swing.JMenuItem(); jMenuItem6 = new javax.swing.JMenuItem(); jMenuItem7 = new javax.swing.JMenuItem();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/javachat/Untitled.jpg"))); // NOI18N

jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/javachat/file_transfer.jpg"))); // NOI18N jLabel2.setText("File transfer");

jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/javachat/text_chat.jpg"))); // NOI18N jLabel3.setText("Chat");

jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/javachat/video_chat.jpg"))); // NOI18N jLabel4.setText("Share Video");

jTextArea1.setColumns(20); jTextArea1.setRows(5); jScrollPane1.setViewportView(jTextArea1);

jTextArea2.setColumns(20);
Page 25

jTextArea2.setEditable(false); jTextArea2.setRows(5); jScrollPane2.setViewportView(jTextArea2);

jTextField1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField1ActionPerformed(evt); } });

jMenu1.setText("Sleeky");

jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ Z, java.awt.event.InputEvent.CTRL_MASK)); jMenuItem1.setText("Sign Out"); jMenu1.add(jMenuItem1);

jMenu4.setText("Close"); jMenu1.add(jMenu4);

jMenuBar1.add(jMenu1);

jMenu2.setText("Contacts");

jMenuItem2.setText("Add Contact");

Page 26

jMenu2.add(jMenuItem2);

jMenuItem3.setText("Delete Contact"); jMenu2.add(jMenuItem3);

jMenuItem4.setText("Block Contact"); jMenu2.add(jMenuItem4);

jMenuBar1.add(jMenu2);

jMenu3.setText("Call");

jMenuItem5.setText("Video Chat"); jMenu3.add(jMenuItem5);

jMenuItem6.setText("Video Sharing"); jMenu3.add(jMenuItem6);

jMenuItem7.setText("Transfer File"); jMenu3.add(jMenuItem7);

jMenuBar1.add(jMenu3);

setJMenuBar(jMenuBar1);

Page 27

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(canvas1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(26, 26, 26) .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE))

Page 28

.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 346, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(canvas1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup() .addGap(36, 36, 36)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 450, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 450, Short.MAX_VALUE)))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(14, 14, 14)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

Page 29

.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE)) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap()) );

pack(); }// </editor-fold>

private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) { typed = jTextField1.getText(); jTextArea1.append(typed+"\n"); jTextField1.setText(""); }

// Variables declaration - do not modify private java.awt.Canvas canvas1;

Page 30

private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu2; private javax.swing.JMenu jMenu3; private javax.swing.JMenu jMenu4; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JMenuItem jMenuItem1; private javax.swing.JMenuItem jMenuItem2; private javax.swing.JMenuItem jMenuItem3; private javax.swing.JMenuItem jMenuItem4; private javax.swing.JMenuItem jMenuItem5; private javax.swing.JMenuItem jMenuItem6; private javax.swing.JMenuItem jMenuItem7; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTextArea jTextArea1; private javax.swing.JTextArea jTextArea2; private javax.swing.JTextField jTextField1; // End of variables declaration

public void actionPerformed(ActionEvent e)

Page 31

{ throw new UnsupportedOperationException("Not supported yet."); }

public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new FriendList().setVisible(true); } }); }

ServerChat.java package javachat;

//~--- non-JDK imports --------------------------------------------------------

Page 32

import com.mysql.jdbc.Connection;

//~--- JDK imports ------------------------------------------------------------

import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage;

import java.io.File; import java.io.IOException;

import java.sql.*;

import java.util.logging.Level; import java.util.logging.Logger;

import javax.imageio.ImageIO;

import javax.swing.*;

/** * * @author Redhot */

Page 33

public class ServerFrame extends JFrame implements ActionListener { private Connection con = null; private ResultSet rs = null; private Statement st = null;

// Variables declaration - do not modify private javax.swing.JButton private javax.swing.JLabel private javax.swing.JLabel private javax.swing.JLabel jButton1; jLabel1; jLabel2; jLabel3;

private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField2; private java.awt.Label private java.awt.Label private java.awt.Label label1; label2; label4;

// End of variables declaration

String

user, upass;

public ServerFrame() { initComponents(); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { connectData();

Page 34

} }); }

@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jLabel3 label1 label2 label4 jLabel1 jButton1 jLabel2 = new javax.swing.JLabel(); = new java.awt.Label(); = new java.awt.Label(); = new java.awt.Label(); = new javax.swing.JLabel(); = new javax.swing.JButton(); = new javax.swing.JLabel();

jTextField1 = new javax.swing.JTextField(); jTextField2 = new javax.swing.JTextField(); jLabel3.setText("jLabel3"); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setFont(new java.awt.Font("Andalus", 1, 18)); label1.setFont(new java.awt.Font("Dialog", 1, 12)); label1.setText("Sleeky ID"); label2.setFont(new java.awt.Font("Dialog", 1, 12)); label2.setText("Sleeky Password"); label4.setFont(new java.awt.Font("DilleniaUPC", 1, 14)); // NOI18N

Page 35

label4.setForeground(new java.awt.Color(204, 0, 51)); label4.setName("sleeky4Pass"); label4.setText("Forgot Your Password ?"); jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/logo.jpg"))); // NOI18N jLabel1.setName("logoLabel"); jButton1.setText("Login"); jButton1.setName("submit"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jLabel2.setFont(new java.awt.Font("DilleniaUPC", 1, 14)); jLabel2.setForeground(new java.awt.Color(153, 0, 0)); jLabel2.setText("Get A Sleeky ID!"); jLabel2.setName("sleekyID"); // NOI18N // NOI18N // NOI18N // NOI18N // NOI18N

jLabel2.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jLabel2MouseClicked(evt); } });

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

Page 36

getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( layout.createSequentialGroup().addContainerGap().addGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( layout.createSequentialGroup().addComponent( jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 167,

javax.swing.GroupLayout.PREFERRED_SIZE).addContainerGap()).addGroup( layout.createSequentialGroup().addGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent( label4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE).addComponent( label1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent( label2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 152,

javax.swing.GroupLayout.PREFERRED_SIZE).addGroup( javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.TRAILING,

Page 37

false).addComponent( jTextField1,

javax.swing.GroupLayout.Alignment.LEADING).addComponent( jLabel1,

javax.swing.GroupLayout.Alignment.LEADING,

javax.swing.GroupLayout.PREFERRED_SIZE, 226,

Short.MAX_VALUE).addComponent( jTextField2,

javax.swing.GroupLayout.Alignment.LEADING).addComponent( jButton1))).addGap( 67, 67, 67))))); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( layout.createSequentialGroup().addGap(96, 96, 96).addComponent( jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE).addGap(27, 27, 27).addComponent( label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(
Page 38

javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent( jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE).addGap(32, 32, 32).addComponent( label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent( jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE).addGap(18, 18, 18).addComponent( jButton1).addGap(41, 41, 41).addComponent(jLabel2).addGap( 21, 21, 21).addComponent( label4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addContainerGap(63, Short.MAX_VALUE))); jLabel2.getAccessibleContext().setAccessibleName("sleekyID"); pack(); } // </editor-fold>

private void jLabel2MouseClicked(java.awt.event.MouseEvent evt) {

// TODO add your handling code here: }

Page 39

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { connectData(); getValues(); getUser(); }

public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new ServerFrame().setVisible(true); } }); }

public void connectData() { try { String userName = "root"; String password = "redhot"; String url = "jdbc:mysql://localhost/sleeky";

Class.forName("com.mysql.jdbc.Driver").newInstance(); con = (Connection) DriverManager.getConnection(url, userName, password); System.out.println("Database connection established"); }

Page 40

catch (Exception e) { System.err.println("Cannot connect to database server"); } }

public void getValues() { user = new String(jTextField1.getText()); upass = new String(jTextField2.getText()); System.out.println(user); }

public void getUser() { try { String s = "select username, password from table_users where username = '"+ user + "' and password = '"+upass+ "'"; st = con.createStatement(); rs=st.executeQuery(s); JOptionPane.showInputDialog("Im here"); rs = st.getResultSet(); while (rs.next()) {

Page 41

System.out.println("Unable to getuser"); } } catch (SQLException ex) { System.out.println("Unable to get catch"); } }

public void actionPerformed(ActionEvent e) { throw new UnsupportedOperationException("Not supported yet."); } }

Signup.java /* * To change this template, choose Tools | Templates * and open the template in the editor. */

/* * signup.java * * Created on Mar 11, 2012, 10:27:30 AM */

Page 42

package javachat;

/** * * @author Redhot */ public class signup extends javax.swing.JFrame {

/** Creates new form signup */ public signup() { initComponents(); }

/** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() {

jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel();

Page 43

jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jTextField2 = new javax.swing.JTextField(); jTextField3 = new javax.swing.JTextField(); jTextField4 = new javax.swing.JTextField(); jTextField5 = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); jLabel7 = new javax.swing.JLabel(); jTextField6 = new javax.swing.JTextField();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setText("Use This Form To Sign Up");

jLabel2.setText("First Name");

jLabel3.setText("Last Name");

jLabel4.setText("User Name");

jLabel5.setText("Email");

Page 44

jLabel6.setText("Password");

jButton1.setText("Submit");

jLabel7.setText("Confirm Password");

jTextField6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField6ActionPerformed(evt); } });

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(42, 42, 42)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2) .addComponent(jLabel3) .addComponent(jLabel4)

Page 45

.addComponent(jLabel5) .addComponent(jLabel6) .addComponent(jLabel7)) .addGap(71, 71, 71)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jTextField5, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE) .addComponent(jTextField4, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE) .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE) .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE) .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE) .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jTextField6))) .addGroup(layout.createSequentialGroup() .addGap(126, 126, 126) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(60, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup()

Page 46

.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(29, 29, 29)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3)) .addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel4)) .addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel5)) .addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

Page 47

.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel6)) .addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE) .addComponent(jButton1) .addContainerGap()) );

pack(); }// </editor-fold>

private void jTextField6ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: }

/** * @param args the command line arguments */ public static void main(String args[]) {

Page 48

java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new signup().setVisible(true); } }); }

// Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField2; private javax.swing.JTextField jTextField3; private javax.swing.JTextField jTextField4; private javax.swing.JTextField jTextField5; private javax.swing.JTextField jTextField6; // End of variables declaration

Page 49

You might also like