📄 tcpapp.tcl
字号:
## Copyright (C) 2001 by USC/ISI# All rights reserved. # # Redistribution and use in source and binary forms are permitted# provided that the above copyright notice and this paragraph are# duplicated in all such forms and that any documentation, advertising# materials, and other materials related to such distribution and use# acknowledge that the software was developed by the University of# Southern California, Information Sciences Institute. The name of the# University may not be used to endorse or promote products derived from# this software without specific prior written permission.# # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.# # @(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/tcl/ex/tcpapp.tcl,v 1.1 2001/11/08 19:43:43 buchheim Exp $ (USC/ISI)# This is a simple demonstration of how to use the TcpApp application# to send data over a TCP connection.set namfile out.namset tracefile out.trset ns [new Simulator]# open trace files and enable tracingset nf [open $namfile w]$ns namtrace-all $nfset f [open $tracefile w]$ns trace-all $f# create two nodesset n0 [$ns node]set n1 [$ns node]$ns duplex-link $n0 $n1 2Mb 5ms DropTail$ns duplex-link-op $n0 $n1 orient right# create FullTcp agents for the nodes# TcpApp needs a two-way implementation of TCPset tcp0 [new Agent/TCP/FullTcp]set tcp1 [new Agent/TCP/FullTcp]$ns attach-agent $n0 $tcp0$ns attach-agent $n1 $tcp1$ns connect $tcp0 $tcp1$tcp1 listen# set up TcpAppset app0 [new Application/TcpApp $tcp0]set app1 [new Application/TcpApp $tcp1]$app0 connect $app1# install a procedure to print out the received dataApplication/TcpApp instproc recv {data} { global ns $ns trace-annotate "$self received data \"$data\""}proc finish {} { global ns nf f namfile $ns flush-trace close $nf close $f puts "running nam..." exec nam $namfile & exit 0}# send a message via TcpApp# The string will be interpreted by the receiver as Tcl code.$ns at 0.5 "$app0 send 100 {$app1 recv {my mesage}}"$ns at 1.0 "finish"$ns run
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -