Tuesday, April 23, 2019


Text Box: 18 April 2019

Implementation of Tcp socket





Client Side Programming

Establish a Socket Connection

To connect to other machine we need a socket connection. A socket connection means the two machines have information about each other’s network location (IP Address) and TCP port.The java.net.Socket class represents a Socket. To open a socket:

Socket socket = new Socket(“127.0.0.1”, 5000)

·         First argument – IP address of Server. ( 127.0.0.1  is the IP address of localhost, where code will run on single stand-alone machine).

·         Second argument – TCP Port. (Just a number representing which application to run on a server. For example, HTTP runs on port 80. Port number can be from 0 to 65535)


To communicate over a socket connection, streams are used to both input and output the data.

Closing the connection

The socket connection is closed explicitly once the message to server is sent.

In the program, Client keeps reading input from user and sends to the server until “Over” is typed.

Java Implementation

filter_none

edit

play_arrow

brightness_4

// A Java program for a Client
import java.net.*;
import java.io.*;
  
public class Client
{
    // initialize socket and input output streams
    private Socket socket            = null;
    private DataInputStream  input   = null;
    private DataOutputStream out     = null;
  
    // constructor to put ip address and port
    public Client(String address, int port)
    {
        // establish a connection
        try
        {
            socket = new Socket(address, port);
            System.out.println("Connected");
  
            // takes input from terminal
            input  = new DataInputStream(System.in);
  
            // sends output to the socket
            out    = new DataOutputStream(socket.getOutputStream());
        }
        catch(UnknownHostException u)
        {
            System.out.println(u);
        }
        catch(IOException i)
        {
            System.out.println(i);
        }
  
        // string to read message from input
        String line = "";
  
        // keep reading until "Over" is input
        while (!line.equals("Over"))
        {
            try
            {
                line = input.readLine();
                out.writeUTF(line);
            }
            catch(IOException i)
            {
                System.out.println(i);
            }
        }
  
        // close the connection
        try
        {
            input.close();
            out.close();
            socket.close();
        }
        catch(IOException i)
        {
            System.out.println(i);
        }
    }
  
    public static void main(String args[])
    {
        Client client = new Client("127.0.0.1", 5000);
    }
}

Server Programming

Establish a Socket Connection

To write a server application two sockets are needed.

·         A ServerSocket which waits for the client requests (when a client makes a new Socket())

·         A plain old Socket socket to use for communication with the client.

Communication

getOutputStream() method is used to send the output through the socket.





Close the Connection

After finishing,  it is important to close the connection by closing the socket as well as input/output streams.



// A Java program for a Server
import java.net.*;
import java.io.*;
  
public class Server
{
    //initialize socket and input stream
    private Socket          socket   = null;
    private ServerSocket    server   = null;
    private DataInputStream in       =  null;
  
    // constructor with port
    public Server(int port)
    {
        // starts server and waits for a connection
        try
        {
            server = new ServerSocket(port);
            System.out.println("Server started");
  
            System.out.println("Waiting for a client ...");
  
            socket = server.accept();
            System.out.println("Client accepted");
  
            // takes input from the client socket
            in = new DataInputStream(
                new BufferedInputStream(socket.getInputStream()));
  
            String line = "";
  
            // reads message from client until "Over" is sent
            while (!line.equals("Over"))
            {
                try
                {
                    line = in.readUTF();
                    System.out.println(line);
  
                }
                catch(IOException i)
                {
                    System.out.println(i);
                }
            }
            System.out.println("Closing connection");
  
            // close connection
            socket.close();
            in.close();
        }
        catch(IOException i)
        {
            System.out.println(i);
        }
    }
  
    public static void main(String args[])
    {
        Server server = new Server(5000);
    }
}









1. First run the Server application as ,

$ java Server

Server started
Waiting for a client …

2. Then run the Client application on another terminal as,

$ java Client

It will show – Connected and the server accepts the client and shows,

Client accepted





3. Then you can start typing messages in the Client window. Here is a sample input to the Client

Hello

I made my first socket connection

Over

Which the Server simultaneously receives and shows,

Hello

I made my first socket connection

Over

Closing connection

Notice that sending “Over” closes the connection between the Client and the Server just like said before.


Tuesday, March 26, 2019


Rip configuration in cisco packet tracer

The Routing Information Protocol (RIP) sends routing-update messages at regular intervals and when the network topology changes. When a device receives a RIP routing update that includes changes to an entry, the deice updates its routing table to reflect the new route. After updating its routing table, the device immediately begins transmitting RIP routing updates to inform other network devices of the change.






Procedure:

  • now drag and drop switches and pcs into the work space
  • connect switches and pcs using copper straight wires in the fast Ethernet ports.
  • provide pc with IP address and gateway to the pcs.

add IP address to the pc by double clicking on the pc and going to IP configuration mode.





  • connect routers and switches using Gigabit port

Configuration of routers: Router 1:

Router(config-if)#exit

Router(config)#interface Serial0/1/1

Router(config-if)#ip address 10.10.10.20 255.0.0.0

Router(config-if)#ip address 10.10.10.20 255.0.0.0

Router(config-if)#no shutdown

Router(config-if)#

%LINK-5-CHANGED: Interface Serial0/1/1, changed state to up



%LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/1/1, changed state to up.
similarly for router 2 has to be done.





CONFIGURATION OF RIP USING CLI IN CISCO PACKET TRACER:

·                                             after the implementation above routing config.go to CLI.

·                                             Type no ip route network_ip network_subnet gateway_router_address.

·                                             router rip and hit enter.

·                                             Type network address subnet etc

·                                             As shown below:





Similary for 2nd router has to be done.

Result:

The RIP is configured.



Implementation of network address translation in cisco packet tracer

 Network address translation (NAT) is a method of remapping one IP address space into another by modifying network address information in the ip header of packets while they are in transit across a traffic routing device. The technique was originally used as a shortcut to avoid the need to readdress every host when a network was moved. It has become a popular and essential tool in conserving global address space in the face of IPv4 address exhaustion. One Internet-routable IP address of a NAT gateway can be used for an entire private network.




Fig1



Types of NAT:

Static NAT: In this, a single private IP address is mapped with single Public IP address, i.e., a private IP address is translated to a public IP address. It is used in Web hosting.

Dynamic NAT: In this type of NAT, multiple private IP address are mapped to a pool of public IP address. It is used when we know the number of fixed users wants to access the Internet at a given point of time.

Procedure:

1.      Drag and drop the network devices to create the above topology using interfaces.

2.      Assign IP Address to the devices as follows:

a.       PC0:  10.0.0.10

b.      PC1:   10.0.0.20

c.       PC3:   10.0.0.30

d.      ROUTER 0 SE 0/1/0 100.0.0.1

e.       ROUTER 0 GIG0/1   10.0.0.1

f.        ROUTER 1 SE0/1/0 100.0.0.2

g.      ROUTER 1 GIG0/1   192.168.1.1

h.      SERVER 0  192.168.1.10

3.      Assign network address to the Router in cli as follows:

·         Router 1:

Router#en

Router#config t

Router(config)#interface Gig0/0

Router(config-if)#ip address 10.0.0.1 255.0.0.0

Router(config-if)#no shutdown

Router(config-if)#exit

Router(config)#interface set0/1/0
Router(config-if)#ip address 100.0.0.2 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#exit



  

   Router 2:

Router#configure terminal
Router(config)#interface gig0/1
Router(config-if)#ip address 192.168.1.1 255.255.255.0
ROUTER(config-if)#no shutdown
ROUTER(config-if)#exit
ROUTER(config)#interface Set0/1/0
ROUTER(config-if)#ip address 100.0.0.2 255.0.0.0
ROUTER(config-if)#no shutdown
ROUTER(config-if)#exit

4. Configure Static NAT:


Static NAT configuration requires three steps: -

  • Define IP address mapping
  • Define inside local interface
  • Define inside global interface
  • Syntax:

Router(config)#ip nat inside source static [inside local ip address] [inside global IP address]

Router 1 NAT configuration:



Result:

Testing Static NAT Configuration:

Type following command in the command prompt.



Router#show ip nat translations

Pro Inside global Inside local Outside local Outside global

--- 50.0.0.10 10.0.0.10 --- ---

--- 50.0.0.20 10.0.0.20 --- ---

--- 50.0.0.30 10.0.0.30 --- ---






 
 
 






Tuesday, March 5, 2019


Implementation of DHCP in cisco packet tracer

Dynamic Host Configuration Protocol (DHCP) is an application layer protocol used to distribute various network configuration parameters to devices on a TCP/IP network. – IP addresses, subnet masks, default gateways, DNS servers, etc

Procedure:

1.      Create the above topology shown using the cisco packet tracer work space.

2.      Assign IP address to the gig interface as following:




3.      A Cisco router can be configured as a DHCP server. Here are the steps:

·         Exclude IP addresses from being assigned by DHCP by using the ip dhcp excluded-address FIRST_IP LAST_IP

·         Create a new DHCP pool with the ip dhcp pool NAME command.

·         Define a subnet that will be used to assign IP addresses to hosts with the network SUBNET SUBNET_MASK command.

·         Define the default gateway with the default-router IP command.

·         Define the DNS server with the dns-server IP address command.

·         (Optional) Define the DNS domain name by using the ip domain-name NAME command.

·         (Optional) Define the lease duration by using the lease DAYS HOURS MINUTES command. If you don’t specify this argument, the default lease time of 24 hours will be used.

 

Router(config-if)#ip dhcp pool IP01
Router(dhcp-config)#net 192.168.100.0 255.255.255.0
Router(dhcp-config)#exit
Router(config)#ip dhcp exec 192.168.100.1 192.168.100.15
^
% Invalid input detected at '^' marker.
Router(config)#ip dhcp exc 192.168.100.1 192.168.100.1
Router(config)#exit
Router#
%SYS-5-CONFIG_I: Configured from console by console



4.      Now click on the generic pc 0 , go to IP configuration and select DHCP.

 Result:

DHCP server has been implemented:



OSPF protocol configuration in cisco packet tracer
The OSPF (Open Shortest Path First) protocol is one of a family of IP Routing protocols, and is an Interior Gateway Protocol (IGP) for the Internet, used to distribute IP routing information throughout a single Autonomous System (AS) in an IP network.


Fig 1:Ospf config

Procedure:
1.      Define the following topology in cisco packet tracer.
2.      Assign IP addresses to the network devices:
      3 . configure router interfaces and switch ports:

For router 0:
Router(config)#int gig 0/1
Router(config-if)#ip add 10.0.0.2 255.0.0.0
Router(config-if)#no shut
Router(config)#interface Serial0/1/0
Router(config-if)#ip address 192.168.1.1 255.255.255.0
Router(config-if)#ip address 192.168.1.1 255.255.255.0
Router(config-if)#no shutdown
Similarly for router 2 as per the given iage below.
Opsf configuration step:
To configure OSPF routing protocol on the above-mentioned topology, you need to perform the following steps.
Router(config)#router ospf <process id 1-65535>
Router(config-router)network <network address> <wild card mask> area <0-4294967295>
1.    Move on to Router1 and execute the following commands to specify the OSPF network and area.
2.    Router1(config)#router ospf 200
3.    Router1(config-router)#network 10.0.0.0 0.255.255.255 area 0
4.    Router1(config-router)#network 192.168.1.0 0.0.0.255 area 0.0.0.0
Router1(config-router)#exit
 Similary for router 2 has to be done .





Tuesday, February 5, 2019

Configure VLANS in Cisco packet tracer

VLAN is a group of devices on one or more LANs that are configured to communicate as if they were attached to the same wire, when in fact they are located on a number of different LAN segments. Because VLANs are based on logical instead of physical connections, they are extremely flexible.

Basic commands used:

Ping : you can send ICMP request to destination and wait for response. 
enable: To enter privileged Exec mode or any other security level.
exit: to close an active terminal.

 Procedure:

  1. Create a network diagram with 4 pcs.
    • select end device option and drag two generic pcs in to the work space.
    • click on the pcs and configure the IP Address of them.
      • for ex : pc1 : IP =192.100.162.10
  2. Connect all the pcs using copper straight wire to the switch. as shown in the figure in fast ethernet port.

  3. Configure the switch using the following caomnds in cci.
    • router> en
    • # config t
    • (config)# int fa 0/1
    • (config -if) vlan 2
    • (config -vlan)#exit
    • (config)# int fa 0/3
      • (config -if) vlan 3
      • (config -vlan)#exit
    • similarly configure other connections.
  4. Now go to command prompt and use ping IP address to trace the packets.

Configuration of router in cisco packet tracer

Routers: A router is a network device that forwards data packets  between computer network. Routers perform the traffic directing functions on the internet . Data sent through the internet, such as a web page or email, is in the form of data packets. A packet is typically forwarded from one router to another router through the networks that constitute an internetwork until it reaches its destination node.

How to configure a router in cisco packet tracer?

fig 1: router configuration.

  • the figure has two routers (namely 1910). taken from the tool box.
  • the HWC2t port is configured by double clicking on the router and dragging the module present on the right on the router. While the router is off
  • connect the router using DCE serial cable.
  • now drag and drop switches and pcs
  • connect switches and pcs using copper straight wires in the fast ethernet ports.
  • provide pc with ip address and gateway to the pcs.
    • add IP address to the pc by double clicking on the pc and going to IP configuration mode.


  • connect routers and switches using Gigabit port.
  • Configuration of routers :
    • enable  (enables the router.)
    • >router # config t       (enters into configuration mod)
    • (#config ) Interface gig 0/1    (enter into interfacing gig port 0/1).
    • #(config-if)IP add 192.168.100.10 255.255.255.0 (assign ip address to the network )
    • #(config -if) no shut (exit out from the config mode).
    • similarly for all the routers.
    • after this config the wire turn green. that means connection is verified.
  • configuring the serial ports of the routers:
    • #interface Serial0/1/0
      Router(config-if)#ip address 192.162.100.10 255.255.255.0
      Router(config-if)#ip address 192.162.100.10 255.255.255.0
      Router(config-if)#no ip address
      no shut.
    • similarly for the other router.
The packets can be verified using the ping command in command prompt.