It was possible to create a bad ref
[jimtcl.git] / examples / udp.client
blobda74e77e08915fd8016904fc7ed96875da576ab1
1 # Example of sending from an unconnected socket
3 set s [socket dgram]
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]
13 $s close
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"
23         $s flush
25         # Receive the response - max length of 100
26         puts [$s recvfrom 100]