On Mon, 29 Sep 1997, Timothy J. Walker wrote:
> Does anyone have any info on how to implement/use
> sockets in tcl/tk. It looks very straight forward :
>
> use the socket command then puts/gets to send/receive.
Funny you should ask. I've just been upgrading TkGnats to talk through
sockets to the gnatsd daemon, and also to talk SMTP directly with an smtp
daemon. Works fine.
> I've tried this and fconfigured the socket every
> which way, but alas my poor server is still so lonely.
> The server responds to the original connect but not the puts !
> Any suggestions ?
Your example looks strange to me. Perhaps this SMTP example will help you.
It's simpler than what you think, I'd say. This example uses \r\n
translation, the normal EOL for unix network protocol (I gather). You can
send the mail a line at a time or all at once. I've left in the
line-at-a-time stuff, but commented out. You can fire up tclsh and paste
in these lines a few at a time. Oh, change the addresses or else I'll
actually get mail from you!
set smtphost your.favorite.mailhost
set s [socket $smpthost 25]
fconfigure $s -buffering line
fconfigure $s -translation crlf
set resp [gets $s]
if {[regexp {^[0-9]+-} $resp]} {
puts "Yes, continuation"
gets $s
} {
puts "No continuation"
}
puts $s "HELO my.place.com"
gets $s
puts $s "MAIL FROM: rickm"
gets $s
puts $s "RCPT TO: rickm"
#puts $s "RCPT TO: [EMAIL PROTECTED]"
#puts $s "RCPT TO: [EMAIL PROTECTED]"
gets $s
puts $s "DATA"
gets $s
#puts $s "From: [EMAIL PROTECTED]"
#puts $s "Reply-To: [EMAIL PROTECTED]"
#puts $s "To: [EMAIL PROTECTED]"
#puts $s "Subject: SMTP test 8 from comsrv1 to cuug"
#puts $s "X-send-pr-version: tkgnats-2.0b7"
#puts $s ""
#puts $s "line 1"
#puts $s "line 2"
#puts $s ""
#puts $s ".."
#puts $s "line 3"
#puts $s "."
set mailtxt ""
append mailtxt "From: [EMAIL PROTECTED]\n"
append mailtxt "Reply-To: [EMAIL PROTECTED]\n"
append mailtxt "To: [EMAIL PROTECTED]\n"
append mailtxt "Subject: SMTP test 8 from comsrv1 to cuug\n"
append mailtxt "X-send-pr-version: tkgnats-2.0b7\n"
append mailtxt "\n"
append mailtxt "line 1\n"
append mailtxt "line 2\n"
append mailtxt "\n"
append mailtxt "..\n"
append mailtxt "line 3\n"
append mailtxt ".\n"
puts $s $mailtxt
puts $s "QUIT"
gets $s
close $s
...RickM...
---------------------------------------------------------------------------
To unsubscribe from the Visual Tcl mailing list, please send a message
to [EMAIL PROTECTED] with "unsubscribe vtcl [EMAIL PROTECTED]" in the
message body (where [EMAIL PROTECTED] is your e-mail address).