1 # Example of sending from an unconnected socket
5 foreach i [range 1 5] {
6 # Specify the address and port with sendto
7 $s sendto "$i + $i + 10" 127.0.0.1:20000
9 # Receive the response - max length of 100
10 puts [$s recvfrom 100]
15 # Now sending via a connected udp socket
17 set s [socket dgram 127.0.0.1:20000]
19 foreach i [range 5 10] {
20 # Socket is connected, so can just use puts here
21 # But remember to flush to ensure that each message is separate
22 $s puts -nonewline "$i * $i"
25 # Receive the response - max length of 100
26 puts [$s recvfrom 100]