Title: Advanced Interactive Programming Componentbased Internet Programming
1Advanced Interactive Programming
Component-based Internet Programming
2Outline
- Fundamental concepts about computer networks
- Architecture
- Communication
- Protocols
- ActiveX controls for Internet programming
- WebBrowser control
- Internet transfer control
- Winsock control
- VBScript Visual Basic Script
3The Internet and WWW
- The Internet
- A massive network of networks, a networking
infrastructure that connects millions of
computers together globally and any computer
communicates with others using a variety of
protocols - The World Wide Web (WWW)
- An information-sharing model and an information
space on top of the Internet - A way of accessing information over the Internet
- Hypertext, HTML, HTTP, URI, Browser, etc.
- The Internet Vs. WWW
- The Web is just a portion of the Internet, albeit
a large portion, but the two terms are not
synonymous and should not be confused - The Internet supports other services, such as
Email, online chat, VoIP, etc.
4Network Architectures
- An architecture refers to a model or structure of
a complex system and also the relationships among
the system components - Client-server architecture
- Computers are either clients or servers
- Clients are less powerful, requesting services
- Servers are powerful, dedicated, serving clients
- Peer to peer architecture (P2P)
- Each computer has equivalent capabilities and
responsibilities
5Client-server Architecture Characteristics
- Server properties
- Passive (Slave)
- Waiting for requests
- On requests serves them and send a reply
- Client properties
- Active (Master)
- Sending requests
- Waits until reply arrives
- Servers can be stateless or stateful
6Peer to Peer Architecture Characteristics
- Pure P2P
- Peers act as either clients or servers
- No central server managing the network
- No central router
- Hybrid P2P
- A central server for peer information
- Peers are responsible for hosting, advertising
and delivering information - Mixed P2P
- Has both pure and hybrid characteristics
7Socket-based Communication
- A socket refers to the combination of a network
address (IP address) and a port - Socket based communication enables applications
to view networking as stream of bytes similar to
file input/output - a program can read from
/write to a socket as simply as reading from /
writing to a file. - Socket based communication is similar to a
telephone call the telephone handset represents
the socket. - The mouthpiece as the output
- The earpiece as the input
- The call, i.e. the connection, terminates by
hanging up the phone
8Socket-based Communication
- Referred to as connection-based or
connection-oriented service - A connection must be established in advance but
can guarantee data flows between processes in
continuous stream - Suitable for transmitting large amount of data
and reliability is imperative - Use TCP protocol
9Packet-based Communication
- Packet-based communication enables applications
to transmit datagrams, i.e. individual packet of
information, between processes without persistent
connections. - It is similar to sending a mail via the postal
service, i.e. a datagram is created, addressed
and sent over the network. - Large data will be broken down into many
datagrams, then sent, and finally reassembled at
the receiving end. - Datagrams may get lost, out of sequence,
duplicate, etc.
10Packet-based Communication
- Referred to as connectionless communication
- Need significant extra programming on the users
part to deal with missing, out-of-sequences, etc.
- Use the User Datagram Protocol (UDP)
- Suitable for transmitting small amount of data or
intermittent data - Usually used for streaming technologies such as
accessing audio and video over the Internet.
11A Typical Process for Socket-based Communication
- A client attempts to establish a connection to a
server. - The server can accept or deny the connection.
- Once connected, socket-based communication begins
to perform business processing. - Both the client and the server need to close the
connection if not needed.
12Some Internet Protocols
- Protocol is a set of rule governing communication
within or between computer endpoints - Internet protocol (IP)
- Used for communicating data across computer
networks - Provide globally unique addresses for networked
computers - Transmission Control Protocol (TCP)
- Create connections between networked computers
- Guarantee reliable and in-order delivery of data
- Distinguish data for multiple concurrent
applications
13Some Internet Protocols
- User Datagram Protocol (UDP)
- Send datagram among networked computers
- Faster and more efficient for lightweight or time
sensitive purpose - Not provide reliable and ordering guarantee as
TCP - HyperText Transfer Protocol (HTTP)
- A method to transfer or convey information on the
WWW, i.e. publish and receive HML pages - a request/response protocol between clients and
servers - File Transfer Protocol (FTP)
- Used to exchange files over any networks that
support TCP/IP - Involve a FTP client and a FTP server
- Upload, download, rename, delete, change
directories, etc.
14Internet Protocol Suite
15VB Internet Controls
16WebBrowser Control
- Enable applications to
- Browse Web sites, view Web pages and download
data located on the Internet, which provides an
application with many features of an Internet
browser - Open any ActiveX document, including Microsoft
Office documents - Open folders on a local hard disk and on a local
area network - Manage navigation, hyperlinking, history lists,
favourites and security
17Example A Simple Web Browser
18Code Example
The same way as creating standard exe applications
Add the WebBrowser control and call correspondent
methods
19Internet Transfer Control
- Enable applications to use HTTP and FTP for
Internet-based applications - That is, applications can retrieve files from and
send files to any site that uses one of these
protocols - Possible uses
- To parse a World Wide Web site for application
specific uses - To present a customized display of dynamic data
retrieved from a Web page. - To add FTP capabilities to any application
- To create an application that automatically
downloads files from a public FTP site
20HTTP Connection Application
- Connect to a Web server using HTTP
- Different from WebBrowser in that it simply
provides the text of the document being retrieved
- Synchronous transfer the program waits for the
transfer to complete
21HTTP Connection Example
- Use Internet Transfer control to download the
content of a file
22HTTP Connection Example
- Create a standard application with the GUI
- Add the Internet Transfer Control to the
application and configure its protocol as HTTP - Call the OpenURL method to download the URL
23FTP Connection Application
- Download files from or upload files to FTP
servers - Support asynchronous transfer, i.e. keep
executing while the server responds to the
requests - Support a number of FTP commands such as get,
push, cd, cdup,, rename, rmdir, quit, etc.
24FTP Connection Example
- Create a standard application with the GUI with
server name, retrieved file name, user name and
password - Add the Internet Transfer Control to the
application and configure its protocol as FTP - Click Get the File to download the specified
file
Download a text file
25Example Code
Set the controls properties
Call the Execute method to download the file
Support asynchronous transfer through the event
procedure StateChanges
26Properties and Methods
27Basic Operations
- The functionality of the Internet Transfer
control depends on the protocol you wish to use. - Set the AccessType property to a valid proxy
server - Invoke the OpenURL method with a valid URL
- Invoke the Execute method with a valid URL and
command appropriate to the protocol - Use the GetChunk method to retrieve data from the
buffer
28The Winsock Control
- Enable applications to connect to a remote
machine and exchange data using either TCP or UDP - Both protocols can be used to create client and
server applications - Possible uses
- Create a client application that collects user
information before sending it to a central server - Create a server application that functions as a
central collection point for data from several
users - Create a server application that provides
services for users - Create a "chat" application
29Establishing a TCP Server
- Step1 create an object of Winsock control in the
application, e.g. tcpServer - Step2 set up the port number of the controls
LocalPort property to listen for connections from
clients - tcpServer.LocalPort 5000
- Step3 tell the server to listen indefinitely for
an attempt of connection - call tcpServer.Listen
30Establishing a TCP Server
- Step4 accept the request for connection from a
client when a connection request is received - Execute event procedure ConnectionRequest
- call tcpServer.Accept(requestID)
- Step5 the processing phase in which the client
and server communicate via the connection - Execute DataArrival event when data arrives at
the server - To retrieve data, use tcpServer.GetData(message
) - To send data, use tcpServer.SendData(message)
- Step6 once transmission is complete and the
client closes the connection, the server also
closes the connection - tcpServer.Close
31Establishing a TCP Client
- Step1 create an object of Winsock control in the
application, e.g. tcpClient - Step2 set up the server to which to connect and
the port number on that server - tcpClient.RemoteHost localhost
- could be server name like www.microsoft.com or
localhost or IP addresses - tcpClient.RemotePort 5000
- march the one assigned in the server
- Step3 connect to the specified server
- tcpClient.Connect
32Establishing a TCP Client
- Once connected successfully
- Step4 the processing phase in which the client
and server communicate via the connection - To retrieve data, use tcpClient.GetData(message)
- To send data, use tcpClient.SendData(message)
- Step5 once transmission is complete and the
server closes the connection, the client also
closes the connection - tcpClient.Close
33Example a TCP-based Chat Program Using Winsock
Control
Client GUI
10 -1
Server GUI
10 - 2
Invisible WinSock object
34Setup the VB Winsock Control
- Properties can be set up in Property Pages or in
program code - Usually invisible
35Example Code for the Server
36Example Code for the Server
37Example Code for the Client
38Example Code for the Client
39Example a TCP-based Chat Program Using Winsock
Control
Client GUI
10 -1
Server GUI
10 - 2
Invisible WinSock object
40(No Transcript)
41Example a UDP-based Chat Program Using Winsock
Control
Client GUI
Server GUI
- Each has two TextBoxes, a Button and a WinSock
control
42Setup the VB Winsock Control
- Properties can be set up in Property Pages or in
program code - Usually invisible
43Example Code for the UDP Server
Specify the port for receiving packets
Close the server
NO CONNECTION
Receive data and display in text box
Send a packet of information
44Example Code for the UDP Client
NO CONNECTION
Specify the server
Specify the port
Close the client
45Example Code for the UDP Client
Receive data and display in text box
Send a packet of information
46Example a UDP-based Chat Program Using Winsock
Control
Client GUI
10 -3
Server GUI
10 -4
47Properties, Methods and Events
48VBScript Visual Basic Script
- What is VBScript?
- VBScript is a scripting language, i.e. a
lightweight programming language - VBScript is a light version of Visual Basic
- Used in client side to enhance the functionality
of a web page - When a VBScript is inserted into a HTML document,
the Internet browser will read the HTML and
interpret the VBScript. The VBScript can be
executed immediately, or at a later event. - Used in server side to enhance the functionality
of server-side applications - Default scripting language for ASP the
server-side technology for dynamically-generated
web pages, which is similar to a HTML file
49VBScript Visual Basic Script
- When a browser requests an ASP file, IIS passes
the request to the ASP engine. The ASP engine
reads the ASP file, line by line, and executes
the scripts in the file. Finally, the ASP file is
returned to the browser as plain HTML - With VBScripts in both client side and
server-side, it is able to dynamically edit,
change or add any content of a Web page, respond
to data submitted from HTML forms, access any
data or databases and return the results to a
browser, customize a Web page to make it more
dynamic, interactive and more useful for
individual users.
50VBScript Language Overview
- A subset of VB
- Use the same VB syntax
- Support many control structures, such as
if/then/else, do/loop, for/next - Support many operators such as arithmetic,
logical, relational operations
51VBScript Language Overview
- Provide many predefined constants, such as color,
date/time, file I/O, etc. - Support user defined constants
- Enable defining variables at multi-levels
- ONLY provide one data type variant that is
capable of storing data of many VB types
52Using VBScript in Web Pages
- VBScripts can be in either HEAD section or BODY
section, normally in HEAD section - Use ltSCRIPTgt with some attributes and HTML
comment tag to mark up
53Example Code
10 -5
54Intrinsic HTML GUI Controls
55Events of HTML GUI Controls
56Tags for HTML GUI Control
- Use INPUT tag within FORM tags to specify HTML
GUI controls in HTML files
57Summary
- Fundamental concepts about Internet programming
- Architecture
- Communication
- Protocols
- ActiveX controls for Internet programming
- WebBrowser control
- Internet transfer control
- Winsock control
- VBScript Visual Basic Script