ActiveState Community

NewBie: TCL, How to program using sockets

Posted by ash5 on 2009-03-24 08:19
OS: All / Any

Hi All,

I am very new to TCL and I have started with socket programming using the sockets.
coming from a .Net background on network programming using windows sockets, I need to implement some code using TCL.

In windows sockets I have the option of selecting the kind of socket using the
SocketType.Stream/Dgram/raw and
ProtocolType.TCP/udp/IP
during creating a new socket.

1. Is there any equivalent thing in TCL?

2. How do I determine the other properties of a TCL 'socket'?

3. I see that TCL sockets are used only for TCP based connections.. am I right? If so what about other kind of protocols.

jeffh | Tue, 2009-03-24 11:05

Do [teacup install udp] to get the tcludp package which enables udp sockets across platforms. See more at http://wiki.tcl.tk/tcludp.

ash5 | Wed, 2009-03-25 00:09

Thanks jeffh..

but I am still wondering how to find a solution for my 1. and 2.
questions.

patthoyts | Thu, 2009-04-09 15:55

read the socket and fconfigure manuals.

eg: make a google search for the manual:

set sock [socket www.google.com 80] ;# open tcp socket
fconfigure $sock -translation crlf -encoding iso8859-1 \
  -blocking 1 -buffering line
puts $sock "GET /search?q=fconfigure HTTP/1.0\nHost: www.google.com\n"
while {[gets $sock line] != -1} {
  puts $line
}
close $sock