Chap 04 Networking Basics
Chap 04 Networking Basics
CHAPTER 04
NETWORKING BASICS
BY
MR.RUPNAR PRAVIN MARUTI
M.TECH CST
The Objectives Of This Chapter Are:
•Well-known ports
•Registered ports
•Dynamic ports
Well-known ports
The range of well-known port is 0 to 1023. The well-known ports are used with
those protocols that serve common applications and services such as
HTTP (hypertext transfer protocol), IMAP (Internet Message Access Protocol),
SMTP (Simple Mail Transfer Protocol), etc. For example, we want to visit some
websites on an internet; then, we use http protocol; the http is available with a port
number 80, which means that when we use http protocol with an application then it
gets port number 80. It is defined that whenever http protocol is used, then port
number 80 will be used. Similarly, with other protocols such as SMTP, IMAP; well-
known ports are defined. The remaining port numbers are used for random
applications.
Registered ports
The range of registered port is 1024 to 49151. The registered ports are used for the user
processes. These processes are individual applications rather than the common
applications that have a well-known port.
Dynamic ports
The range of dynamic port is 49152 to 65535. Another name of the dynamic port is
ephemeral ports. These port numbers are assigned to the client application dynamically
when a client creates a connection. The dynamic port is identified when the client
initiates the connection, whereas the client knows the well-known port prior to the
connection. This port is not known to the client when the client connects to the service.
Proxy Server
The proxy server is like an intermediate system between the client-side application and
other servers. In an enterprise application, which is used to provide control over the
user's content across network boundaries. The below image demonstrates the behavior
of the proxy server:
Advantages of Using Proxy Servers
Devices connected to the Internet are called nodes. Nodes that are computers are
called hosts. Each node or host is identified by at least one unique number called an
Internet address or an IP address. Most current IP addresses are 4-byte-long IPv4
addresses. However, a small but growing number of IP addresses are 16-byte-long IPv6
addresses. (4 and 6 refer to the version of the Internet Protocol, not the number of the
bytes in the address.) Both IPv4 and IPv6 addresses are ordered sequences of bytes, like
an array. They aren’t numbers, and they aren’t ordered in any predictable or useful
sense.
TRADITIONAL COMMUNICATION
Protocol
communication
TRADITIONAL COMMUNICATION
Class Use
Interface Use
CookiePolicy implementations decide which
CookiePolicy cookies should be accepted and which should be
rejected.
A CookieStore object represents storage for
CookieStore
cookie.
DatagramSocketImplFact This interface defines a factory for datagram
ory socket implementations.
A simple interface which provides a mechanism to
FileNameMap map between a file name and a MIME(Multipurpose
Internet Mail Extensions) type string.
This interface defines a factory for socket
SocketImplFactory
implementations.
SocketOptions Interface of methods to get/set socket options.
URLStreamHandlerFactor This interface defines a factory for URL stream
y protocol handlers.
4.3 INETADDRESS CLASS
Method Description
public static InetAddress It returns the instance of InetAddress
getByName(String host) throws containing LocalHost IP and name.
UnknownHostException
public static InetAddress It returns the instance of InetAdddress
getLocalHost() throws containing local host name and address.
UnknownHostException
public String getHostName() It returns the host name of the IP
address.
public String getHostAddress() It returns the IP address in string format.
INSTANCE METHODS
Method
Description
getHostName() This method returns the host name for this IP address.
This method used to check if the InetAddress
isLoopbackAddress()
represents a loopback address.
This method checks whether the site has multiple
isMulticastAddress()
servers.
isReachable(int
This method tests whether that address is reachable.
timeout)
TCP/IP CLIENT SOCKET
The ServerSocket class can be used to create a server socket. This object is
used to establish communication with the clients.
Important methods
Method Description
1) public Socket accept() returns the socket and establish a
connection between server and
client.
2) public void close() closes the server socket.
Example of Java Socket Programming
Creating Server:
scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]
1.scheme : The scheme component lays out the protocols to be associated with the URI.
3.path : The path represents a string containing the address within the server to the resource.
4.query : Query represent a nonhierarchical data usually the query used for searching of a
particular resource. They are separated by a ‘?’ from the preceding part.
Syntax :
public URI(String str) throws URISyntaxException
Constructors
Constructor Description
The send( ) method sends packet to the port specified by packet. The receive method
waits for a packet to be received from the port specified by packet and returns the result.
DatagramPacket defines several constructors. Four are shown here:
DatagramPacket(byte data[ ], int size) : It specifies a buffer that will receive data and the
size of a packet. It is used for receiving data over a DatagramSocket
DatagramPacket(byte data[ ], int offset, int size) : It allows you to specify an offset into
the buffer at which data will be stored.
DatagramPacket(byte data[ ], int offset, int size, InetAddress ipAddress, int port) : It
transmits packets beginning at the specified offset into the data.
Function Usage
Returns the address of the source (for datagrams being
InetAddress getAddress( )
received) or destination (for datagrams being sent).
Returns the byte array of data contained in the datagram.
byte[ ] getData( ) Mostly used to retrieve data from the datagram after it has
been received.
Returns the length of the valid data contained in the byte
int getLength( ) array that would be returned from the getData( ) method.
This may not equal the length of the whole byte array.
void setAddress(InetAddress Sets the address to which a packet will be sent. The
ipAddress) address is specified by ipAddress.
Sets the data to data, the offset to zero, and the length to
void setData(byte[ ] data)
number of bytes in data
void setData(byte[ ] data, int Sets the data to data, the offset to idx, and the length to
idx, int size) size.