Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to do data transmission between the nodes using TCP in NS2?

  • The nodes can be communicate in ns2 using the communication model that consists of TCP agent, TCPSink agent, and FTP application.

    set ns [new Simulator]
    set node_(0) [$ns node]
    set node_(1) [$ns node]
    # Defining a transport agent for sending
    set tcp [new Agent/TCP]
    # Attaching transport agent to sender node
    $ns attach-agent $node_(0) $tcp
    # Defining a transport agent for receiving
    set sink [new Agent/TCPSink]
    # Attaching transport agent to receiver node
    $ns attach-agent $node_(1) $sink
    # Connecting sending and receiving transport agents
    $ns connect $tcp $sink
    # Defining Application instance
    set ftp [new Application/FTP]
    # Attaching transport agent to application agent
    $ftp attach-agent $tcp
    # data packet generation starting time
    $ns at 1.0 "$ftp start"
    # data packet generation ending time
    $ns at 6.0 "$ftp stop"
    where,
    ns → Simulator instance
    TCP → Transmission Control Protocol
    FTP → File Transfer Protocol