diff --git a/doc/openocd.texi b/doc/openocd.texi
index 160efa650814842466ee3506f686481ef71c2c38..573457b5e9f31ec72e00a49a359d874e9d9efb7c 100644
--- a/doc/openocd.texi
+++ b/doc/openocd.texi
@@ -1381,7 +1381,7 @@ of an external TCL script that can connect to openocd is shown below.
 @verbatim
 # Simple tcl client to connect to openocd
 puts "Use empty line to exit"
-set fo [socket 127.0.0.1 5555]
+set fo [socket 127.0.0.1 6666]
 puts -nonewline stdout "> "
 flush stdout
 while {[gets stdin line] >= 0} {
diff --git a/testing/tcl_server.tcl b/testing/tcl_server.tcl
new file mode 100644
index 0000000000000000000000000000000000000000..c5ec229171bc09689e69f8faf3111620440866b0
--- /dev/null
+++ b/testing/tcl_server.tcl
@@ -0,0 +1,15 @@
+# Simple tcl client to connect to openocd
+puts "Use empty line to exit"
+set fo [socket 127.0.0.1 6666]
+puts -nonewline stdout "> "
+flush stdout
+while {[gets stdin line] >= 0} {
+    if {$line eq {}} break
+    puts $fo $line
+    flush $fo
+    gets $fo line
+    puts $line
+    puts -nonewline stdout "> "
+    flush stdout
+}
+close $fo