File: udp6.server

package info (click to toggle)
openocd 0.9.0-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 24,876 kB
  • sloc: ansic: 275,029; sh: 15,664; tcl: 7,079; asm: 1,913; cpp: 1,671; makefile: 1,200; perl: 717; python: 708; haskell: 35
file content (26 lines) | stat: -rw-r--r-- 596 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Example of a udp server listening on ipv6 which sends a response
# Note that on many hosts, this will also respond to ipv4 requests too

# Listen on port 20000.
set s [socket -ipv6 dgram.server {[::]:20000}]

# For each request...
$s readable {
	# Get the request (max 80 chars) - need the source address
	set buf [$s recvfrom 80 addr]

	puts -nonewline "read '$buf' from $addr"

	try {
		set result "$buf = [expr $buf]"
	} on error {msg} {
		set result "Error: $buf => $msg"
	}

	puts ", sending '$result'"

	# Send the result back to where it came from
	$s sendto $result $addr
}

vwait done