Created
September 25, 2012 22:02
-
-
Save ncimino/3784751 to your computer and use it in GitHub Desktop.
Client Side - Tcl
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/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