Created
August 2, 2016 17:29
-
-
Save mutability/95e068be1908a53196efd1d54f34cc01 to your computer and use it in GitHub Desktop.
quick adept client tester
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env tclsh8.6 | |
package require tls | |
proc testit {host port} { | |
puts "connecting to $host $port" | |
set sock [tls::socket -cipher ALL \ | |
-ssl2 0 \ | |
-ssl3 0 \ | |
-tls1 1 \ | |
-require 1 \ | |
-command tls_callback $host $port] | |
puts "connected, handshaking" | |
tls::handshake $sock | |
fconfigure $sock -blocking 0 -buffering full -buffersize 4096 -translation binary | |
set message(type) login | |
set message(mac) "00:00:00:00:00:00" | |
set message(clock) [clock seconds] | |
set out "" | |
foreach field [lsort [array names message]] { | |
append out "\t$field\t$message($field)" | |
} | |
set out [string range $out 1 end] | |
puts "sending login message: $out" | |
puts $sock [string range $out 1 end] | |
flush $sock | |
puts "waiting for data" | |
fileevent $sock readable [list read_callback $sock] | |
} | |
proc tls_callback {args} { | |
puts "tls_callback: $args" | |
return 1 | |
} | |
proc read_callback {sock} { | |
if {[eof $sock]} { | |
puts "Got EOF from server" | |
set ::die 1 | |
return | |
} | |
if {[catch {set size [gets $sock line]} catchResult] == 1} { | |
puts "caught an error from gets: $catchResult" | |
set ::die 1 | |
return | |
} | |
if {$size < 0} { | |
puts "got a readable event, but a complete line wasn't ready" | |
return | |
} | |
puts "Got a line: $line" | |
} | |
if {!$tcl_interactive} { | |
testit "piaware.flightaware.com" 1200 | |
vwait ::die | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment