fall 2005csi 4118 – university of ottawa1 computer networks & protocols (csi 4118) fall 2005...
TRANSCRIPT
![Page 1: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/1.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 1
Computer Networks & PROTOCOLS
(CSI 4118)
FALL 2005
Professor Robert L. Probert
![Page 2: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/2.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 2
Part I
Introduction
![Page 3: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/3.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 3
Topic and Scope
Computer networks and internets: an overview of concepts, terminology, and technologies that form the basis for digital communication in private corporate networks and the global Internet.
![Page 4: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/4.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 4
You Will Learn
Internets and Internetworking Motivation and concept Internet Protocol (IP) datagram format and addressing Internet routers and routing Address binding (ARP) Internet control messages (ICMP) User Datagram Protocol (UDP) Transmission Control Protocol (TCP) Protocol ports and demultiplexing
![Page 5: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/5.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 5
You Will Learn (continued)
Some network applications! Client-server paradigm Domain name system (DNS) File transfer (FTP) Remote login (TELNET) Email transfer (SMTP) Web technologies and protocols
HTTP, PHP, CGI, Java Security Voice over IP, …
![Page 6: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/6.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 6
Background Required
Ability to program in Java, ability to read C code Knowledge of low-level programming constructs
Pointers Bit fields in structures
Familiarity with basic tools Text editor Compiler / linker / loader
![Page 7: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/7.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 7
Background Required (continued)
Basic knowledge of operating systems Terminology Functionality Processes and concurrent processing
CSI 3103/3503
![Page 8: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/8.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 8
Motivation for Networking
Information access Interaction among cooperative application
programs Resource sharing
![Page 9: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/9.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 9
The Internet conceptthe illusion of a single network that TCP/IP software provides to users and applications
User’scomputers
![Page 10: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/10.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 10
The Internet conceptthe underlying physical structure in which a computer attaches to one physical network and routers interconnect the networks
Net 3
Net 1 Net 2
Net 5
Net 4
Net 1
router
Physical net
![Page 11: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/11.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 11
Figure 2.1
![Page 12: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/12.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 12
Figure 2.2
![Page 13: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/13.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 13
Figure 2.3
![Page 14: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/14.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 14
Figure 2.4
![Page 15: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/15.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 15
Figure 2.5
![Page 16: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/16.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 16
Figure 2.6
![Page 17: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/17.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 17
Practical Examples
Email File transfer / access Web browsing Remote login / execution
![Page 18: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/18.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 18
What is a Network?
Transmission hardware (media) [Ch. 4] Special-purpose hardware devices [Ch. 9, 10]
Interconnect transmission media Control transmission Run protocol software
Protocol software [Ch. 16 and following] Encodes and formats data Detects and corrects problems
![Page 19: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/19.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 19
What does a Network Do?
Provides communication that is Reliable Fair Efficient [15.14] From one application to another
(allows arbitrary applications to communicate via Network (Distributed) Programming)
![Page 20: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/20.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 20
What Does a Network Do?
Reliable Fair Efficient
Delay Throughput
![Page 21: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/21.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 21
Delay and Throughput Delay
Propagation Delay Switching Delay Access Delay Queuing Delay
Throughput Rate of Data Transmission How many bits can enter (or leave) network in fixed unit of time Effective Throughput Capacity Congestion Degree of Utilization
![Page 22: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/22.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 22
What Does a Network Do? (continued)
Automatically detects and corrects Data corruption e,g., CRC [7.9, 7.10] Data loss Duplication Out-of-order delivery e.g., sequencing [16.10]
Automatically finds optimal path from source to destination, routing [Ch. 13]
![Page 23: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/23.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 23
Network (Distributed) Programming [Ch. 3]
Network allows arbitrary applications to communicate
Programmer does not need to understand network technologies
Network facilities are accessed through an Application Program Interface
![Page 24: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/24.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 24
Basic Paradigm for Pairwise Internet Communication
Establish contact Exchange data (bi-directional) Terminate contact
Note: NO data processing by the network
![Page 25: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/25.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 25
Establishing Contact
Performed by pair of applications One application waits for contact (called
server) Other application initiates contact (called
client)
![Page 26: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/26.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 26
Identifying a Waiting Application
Conceptually two items specified Computer Application on that computer
Terminology Computer identified by domain name Application identified by program name
![Page 27: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/27.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 27
Representations and Translations
Humans use names such as computer: www.netbook.cs.purdue.edu application: ftp
Network protocols require binary values Library routines exist to translate from names
to numbers
![Page 28: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/28.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 28
Example API
![Page 29: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/29.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 29
Simplified API
![Page 30: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/30.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 30
Simplified API (Cont’d)
![Page 31: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/31.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 31
Simplified API (Cont’d)
The Await_Contact Function
connection await_contact(appnum a)
The argument specifies a number that identifies the server application
![Page 32: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/32.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 32
Simplified API (Cont’d)
The Make_Contact Function
connection make_contact(computer c, appnum a)
The client uses the return value, which is of type connection, to transfer data
![Page 33: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/33.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 33
Simplified API (Cont’d)
The appname_to_appnum Function
appnum appname_to appnum(char *a)
Clients and servers both use appname_to_appnum to translate from a human-readable name for a service to an internal binary value
![Page 34: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/34.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 34
Simplified API (Cont’d)
The Cname_to_comp Function
computer cname_to_comp(char *c)
Clients call cname_to_comp convert from a human-readable computer name to the internal binary value
![Page 35: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/35.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 35
Simplified API (Cont’d)
The Send Function
int send (connection con, char *buffer, int length, int flags)
Both clients and servers use send to transfer data across the network
![Page 36: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/36.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 36
Simplified API (Cont’d)
The Recv And Recvln Function
int recv (connection con, char *buffer, int length, int flags)
Both clients and servers use recv to access data that arrives across the network
int recvln (connection con, char *buffer, int length)
Recvln repeatedly calls recv until an entire line of test has been received
![Page 37: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/37.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 37
Simplified API (Cont’d)
The Send_eof Function
int send_eof (connection con)
Both the client and server must use send_eof after sending data to inform the other side that no further transmission will occur
![Page 38: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/38.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 38
Simplified API (Cont’d)
![Page 39: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/39.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 39
![Page 40: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/40.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 40
Example #1: Echo
Useful for network testing Server returns exact copy of data sent User on computer X runs
echoserver 22000 User on another computer runs
echoclient X 22000
![Page 41: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/41.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 41
Example Code Using API: Echoserver
![Page 42: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/42.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 42
Echoserver (2 of 2)
Actually works on the Internet API calls replace conventional I/O No networking knowledge required
![Page 43: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/43.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 43
Example #2: Chat
Miniature version of Internet chat service Allows two users to communicate User on computer X runs
chatserver 25000 User on another computer runs
chatclient X 25000
![Page 44: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/44.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 44
Example Application: Web Server
User on computer X runs
webserver 27000 User on another computer runs browser and
enters URL:
http://X:27000/index.html
![Page 45: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/45.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 45
Example Code Using API: Webserver
![Page 46: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/46.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 46
Webserver (2 of 6)
![Page 47: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/47.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 47
Webserver (3 of 6)
![Page 48: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/48.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 48
Webserver (4 of 6)
![Page 49: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/49.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 49
Webserver (5 of 6)
![Page 50: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/50.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 50
Webserver (6 of 6)
![Page 51: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/51.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 51
Network Programming in Java
The java.net package provides two classes--Socket and ServerSocket--that implement the client side of the connection and the server side of the connection, respectively.
java.io package also has to be used together with socket API.
![Page 52: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/52.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 52
Example API in Java (v1.3+)
Method Class Meaning Socket (String host, int port) java.net.Socket Used by client to create a socket
to connect to the specified server host and port
ServerSocket (int port) java.net.ServerSocket Used by server to create a socket on a specified port
accept java.net.ServerSocket Used by server to accept connection from client
println java.io.PrintWriter java.io.PrintStream
Used by either client or server to send data
readLine java.io.BufferedReader Used by either client or server to receive data
close java.net.Socket
Used by client to close this socket
close java.net.ServerSocket Used by server to close this socket
![Page 53: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/53.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 53
The steps for programming in Java:
1. Open a socket. 2. Open an input stream and output stream to the
socket. 3. Read from and write to the stream according to
the server's protocol. 4. Close the streams. 5. Close the socket.
![Page 54: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/54.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 54
Example Code Using Java API:(1) EchoServer.javaimport java.io.*;import java.net.*;public class EchoServer { public static void main(String args[]) { // declare a server socket and a client socket for the server ServerSocket echoServer = null;
String line; BufferedReader br; PrintStream os; Socket clientSocket = null;
// open a server socket on a specfic port. args[0] is the port
number try {
echoServer = new ServerSocket(Integer.parseInt(args[0]));
} catch (IOException e) { }
![Page 55: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/55.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 55
try { // open a socket to listen and accept connections from
client
clientSocket = echoServer.accept();
br = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
os = new PrintStream(clientSocket.getOutputStream());
// once receiving data from client, echo it back to the client.
while (true) {
line = br.readLine();
os.println(line);
} } catch (IOException e) { }
}//EchoServer.java
![Page 56: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/56.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 56
(2) EchoClient.javaimport java.io.*;import java.net.*;
public class EchoClient {
public static void main(String[] args) throws IOException { Socket echoSocket = null; PrintWriter out = null; BufferedReader in = null;
//open a socket to a specified host and port.
try { // args[0] is host address, args[1] is port number
echoSocket = new Socket(args[0], Integer.parseInt(args[1]));
out = new PrintWriter(echoSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader( echoSocket.getInputStream()));
} catch (Exception e) {}
![Page 57: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/57.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 57
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
String userInput;
//send user's input to server, and retrieve what the server sends back. while ((userInput = stdIn.readLine()) != null) {
out.println(userInput);System.out.println("echo: " + in.readLine());
}
//close everything gracefully out.close(); in.close(); stdIn.close(); echoSocket.close(); } }//EchoClient.java
![Page 58: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/58.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 58
(3) Test Run 1. Compile EchoServer.java and EchoClient.java.
2. Start server program: java EchoServer localhost 4118
3. Start client program: java EchoClient 4118 Then type in something at prompt to see what
will happen.
![Page 59: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/59.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 59
Summary
Studying networks is important because The world is interconnected Applications now operate in a distributed
environment This course
Covers networking and internetworking Explains the mystery of applications Will be hard work
![Page 60: FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert](https://reader038.vdocument.in/reader038/viewer/2022102719/5697bf731a28abf838c7f1ab/html5/thumbnails/60.jpg)
FALL 2005 CSI 4118 – UNIVERSITY OF OTTAWA 60
Summary (continued)
Computer Internetworks Deliver data from source to destination Automatically find optimal paths Handle problems that occur
We will review how