Research breakthrough possible @S-Logix

Office Address

  • 2nd Floor, #7a, High School Road, Secretariat Colony Ambattur, Chennai-600053 (Landmark: SRM School) Tamil Nadu, India
  • +91- 81240 01111

Social List

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


In a wireless network, nodes communicate using the communication model that consists of TCP agent, TCPSink agent, and FTP application. The sender node is attached to the TCP agent while the receiver node is attached to the TCPSink agent. The connection between TCP agent and TCPSink agent is established using the keyword “connect”. Transport agent (TCP) and application (FTP) are connected using the keyword “attach-agent”. TCP agent sends data to TCPSink agent. On receiving the data packet, TCPSink agent sends the acknowledgement to the TCP agent that in turn processes the acknowledgements and adjusts the data transmission rate. The lost packets interpreted as a sign of congestion. The tcl script in sample5.tcl demonstrates the communication between the nodes using TCP protocol.

Sample Code

#Filename: sample5.tcl

TCP (Transmission Control Protocol) and FTP (File Transfer

Protocol) ************#

#*****defining Communication between node0 and node1 **********#

# 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"


data transmission between nodes using TCP in NS2