johnlopez2000
Programmer
Colleagues,
just need a little help with sockets.
Trying to get a client/server connection via 2 TCL sessions and I think I am missing something:
#------------------------------------
#server
set host 127.0.0.1
set port 5001
set socket [socket -server $host $port]
fconfigure $socket -blocking 1 -translation auto
gets $socket bytes
set msg [read $socket $bytes]
puts $msg
#------------------------------
#client
set host 127.0.0.1
set port 5001
set socket [socket $host $port]
fconfigure $socket -blocking 1 -translation auto
set msg [list HELLO 1.0 $tcl_version]
puts $socket [string length $msg]
puts $socket $msg
flush $socket
close $socket
#--------------------------------------
When the server does the GETS, I get the following error:
% gets $socket bytes
channel "sock376" wasn't opened for reading
I assume that I am doing something wrong with the "fconfigure" command, assuming that this sets up read/write operations with the port.
Also, how does one:
a) cause GETS to wait for an incomming connection?
b) do you loop to GET multiple incoming connections?
c) if one wants bi-directional messaging, does one need run a "client" and "server" thread on each side?
Thanks very much for your help.
PS: Example code that works would be a big bonus!
John Lopez
Enterprise PDM Architect
lopez.john@goodrich.com
just need a little help with sockets.
Trying to get a client/server connection via 2 TCL sessions and I think I am missing something:
#------------------------------------
#server
set host 127.0.0.1
set port 5001
set socket [socket -server $host $port]
fconfigure $socket -blocking 1 -translation auto
gets $socket bytes
set msg [read $socket $bytes]
puts $msg
#------------------------------
#client
set host 127.0.0.1
set port 5001
set socket [socket $host $port]
fconfigure $socket -blocking 1 -translation auto
set msg [list HELLO 1.0 $tcl_version]
puts $socket [string length $msg]
puts $socket $msg
flush $socket
close $socket
#--------------------------------------
When the server does the GETS, I get the following error:
% gets $socket bytes
channel "sock376" wasn't opened for reading
I assume that I am doing something wrong with the "fconfigure" command, assuming that this sets up read/write operations with the port.
Also, how does one:
a) cause GETS to wait for an incomming connection?
b) do you loop to GET multiple incoming connections?
c) if one wants bi-directional messaging, does one need run a "client" and "server" thread on each side?
Thanks very much for your help.
PS: Example code that works would be a big bonus!
John Lopez
Enterprise PDM Architect
lopez.john@goodrich.com