TCP Socket Programming STC PLB
TCP Socket Programming STC PLB
Network
Programming
Dr. Padmalochan Bera
Associate Professor (CSE)
School of Electrical and Computer Sciences
IIT Bhubaneswar
TCP/IP
TCP/UDP
TCP/UDP
Process Communication
Process Communication
Berkley Sockets
Sockets
Client Server Communication
Socket Procedures
Client Server Communication
Socket Creation in C
Socket close
Specifying Address
Assigning Address to Socket:
bind( )
bind( ) example
Skipping bind( )
Assigning Address to Socket:
bind( )
Establish Connection: connect( )
Accepting Connection: accept( )
Exchanging Data with stream
socket
Exchanging Data with datagram
socket
Example: Echo server
Example: Echo server using
stream socket
Example: Echo server using
stream socket
Example: Echo server using
stream socket
Example: Echo server using
stream socket
Example: Echo server using
stream socket
Example: Echo server using
stream socket
Dealing with Blocking Calls
Dealing with Blocking Calls
Non-blocking sockets
Signals
Asynchronous I/O
Timeouts
Multi-tasking per Client Process
Example: Multi-tasking
Example: Multi-tasking
Multi-tasking per client thread
Multiple Recipients
Multiple Recipients: Broadcast
Multiple Recipients: Multicast
The End
Introduction
• NS2 history
– Modified from REAL network simulator
– Developed through VINT project at UCB
– NS1 vs. NS2
n0
n1
Step 3: Create Network n0
• Nodes
– set n0 [$ns node]
– set n1 [$ns node] n1
• For example:
• CBR udp
• FTP tcp
• Telnet
– set telnet [new
Application/Telnet] n1
– $telnet attach-agent $tcp
sink
Recall: Generic Script Structure
1. set ns [new Simulator]
2. Turn on tracing
3. Create topology
4. Setup link dynamics
5. Create agents
6. Create application and/or traffic sources
7. Post-processing procedures (i.e. nam)
Examples
8. Start simulation
Post-Processing Procedures
• Add a 'finish' procedure that closes the trace
file and starts nam.
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam out.nam &
exit 0
}
Run Simulation
• Schedule Events
$ns at <time> <event>
– <event>: any legitimate ns/tcl commands
• Call ‘finish’
$ns at 5.0 "finish"