Skip to content

Instantly share code, notes, and snippets.

@ncimino
Created September 25, 2012 22:02
Show Gist options
  • Select an option

  • Save ncimino/3784751 to your computer and use it in GitHub Desktop.

Select an option

Save ncimino/3784751 to your computer and use it in GitHub Desktop.
Client Side - Tcl
#!/usr/bin/tclsh
proc read_sock {sock} {
set l [gets $sock]
puts stdout "ServerReply:$l"
}
proc read_stdin {wsock} {
global eventLoop
set l [gets stdin]
if {[eof stdin]} {
close $wsock ;# close the socket client connection
set eventLoop "done" ;# terminate the vwait (eventloop)
} else {
puts $wsock $l ;# send the data to the server
}
}
set eshost "127.0.0.1"
set esport 8001
set esvrSock [socket $eshost $esport]
fileevent $esvrSock readable [list read_sock $esvrSock]
fconfigure $esvrSock -buffering line
fileevent stdin readable [list read_stdin $esvrSock]
puts "EchoServerClient Connected to echo server"
puts "...what you type should be echoed."
vwait eventLoop
#set esvrSock [socket -async $eshost $esport]
#fileevent $esvrSock writable { set connect 1 }
#vwait connect
#fileevent $esvrSock writable {}
#if {[eof $esvrSock]} { # connection closed .. abort }
#fconfigure $esvrSock -translation {auto crlf} -buffering line
puts "Client Finished"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment