Академический Документы
Профессиональный Документы
Культура Документы
And
Socket Programming
1
Objectives of This Session
2
Host based Processing
Application
Server Logic Data
Mainframe
Clients
3
Client - Server
DBMS
Application
Logic
Network Server
4
Web Based Architecture
HTTP UNIX
TCP/IP
WEB SERVER
INTERNET
WINDOWS
5
Protocol
6
OSI (Open System Interconnection)Model
APPLICATION
PRESENTATION
SESSION
TRANSPORT
NETWORK
DATA LINK
PHYSICAL
7
The OSI Layers
8
TCP/IP Architecture
APPLICATION LAYER
TRANSPORT LAYER
NETWORK LAYER
LINK LAYER
9
IP Addressing Scheme (IPV4)
CLASSSES OF IP ADDRESSES
CLASS A 0 Net id Host id Large size N/W
A 0.0.0.0 to 127.255.255.255
B 128.0.0.0 to 191.255.255.255
C 192.0.0.0 to 223.255.255.255
D 224.0.0.0 to 239.255.255.255
10
TCP/IP Architecture
TCP UDP
ICMP
ARP RARP
11
FTP - File Transport Protocol at the application layer.
Telnet - Remote session at the application layer.
SMTP - Simple Mail Transport Protocol at the application layer.
UDP - User Datagram Protocol is a connection less unreliable protocol working at
the transport layer.
ICMP - Internet Control Message Protocol is used to perform network error
reporting and status. It works at the transport layer.
IP - Internet Protocol is used for software addressing of computers and works at
the data link layer.
ARP - Address Resolution Protocol is used to resolve the hardware address of a
card to package the Ethernet data. It works at the data link layer.
RARP - Reverse Address Resolution Protocol used for disk less computers to
determine their IP address using the network. It works at the data link layer.
NNTP - Network News Transport Protocol is used to link newsgroups for
discussions on the web.
12
SNMP : The Simple Network Management Protocol (SNMP) is an
application layer protocol that facilitates the exchange of management
information between network devices. It is part of the Transmission Control
Protocol/Internet Protocol (TCP/IP) protocol suite. SNMP enables network
administrators to manage network performance, find and solve network
problems, and plan for network growth.
13
TCP protocol
14
UDP protocol
Connectionless protocol.
Relies on IP for addressing & routing
If you send datagram over a UDP protocol, it may
not arrive, if it does, it may arrive out of order etc.
E.g.’s of app’s that run on top of UDP:
SNMP, TFTP
15
Server
16
Client
Request
client Server
Response
17
Client Side Scripts
HTML
Javascript
VB script
Jscript
Applets
18
Socket & Port
19
Port
for example
• 21 – FTP
• 23 – Telnet
• 25 – SMTP
• 80 – HTTP
• 109 - POP
20
Sockets
23
ServerSocket class
24
ServerSocket class
ServerSocket(int port)
ServerSocket(int port, int maxQueue)
ServerSocket(int port, int maxQueue, InetAddress
localAddress)
Socket accept()
25
Socket Programming( Writing Server)
26
Socket Programming ( Writing Client)
Create a Socket
Get I/O streams
Read/Write data
Close the connection
27
java.net classes
InetAddress ServerSocket
DatagramPacket Socket
DatagramSocket SocketImpl
DatagramSocketImpl URL
MulticastSocket URLConnection
28
InetAddress class
29
InetAddress class – Factory Methods
InetAddress getByName(<url>)
InetAddress[ ] getAllByName(String hostname)
(All addresses that a particular name resolves to)
InetAddress getLocalHost()
30
InetAddress class – Instance Methods
31
URL
32
URL class constructors
URL(String urlSpecifier)
33
URL class instance methods
String getProtocol()
int getPort()
String getHost()
String getFile()
String getRef()
URLConnection openConnection()
34
URLConnection class
35
Methods in URLConnection class
36
Datagrams
37
DatagramSocket
38
Methods of DatagramSocket class
39
DatagramPacket
40
Socket Programming
41
Methods of DatagramPacket
InetAddress getAddress()
Returns destination Inetaddress,typically used for sending.
int getPort()
Returns the port number
byte[] getData()
Returns data contained in datagram(after receiving)
int getLength()
Returns length of valid data contained in the byte array
that's returned from getData() method.
42
Socket Programming
ds.receive(receivePacket);
ds.send(receivePacket);
receivePacket.getAddress();
receivePacket.getPort();
receivePacket.getLength();
receivePacket.getData();
43