Tools Command Language

TCL-TK-Socket Programming


s1.tcl

proc read_sock { sock } {
set l [gets $sock]
.eval.t insert insert $l
.eval.t insert insert \n
}
frame .eval
set _t [text .eval.t -width 40 -height 15 -yscrollcommand {.eval.s set} ]
scrollbar .eval.s -command {.eval.t yview}
pack .eval.s -side left -fill y
pack .eval.t -side right -fill both -expand true
pack .eval -fill both -expand true
set eshost "www.microsoft.com"
set esport 80
set esvrSock [socket $eshost $esport]
fileevent $esvrSock readable [list read_sock $esvrSock]
fconfigure $esvrSock -buffering line
set a "GET /intdev/"
puts $esvrSock $a

s2.tcl
proc read_sock { sock } {
set l [gets $sock]
.l insert end  $l
}
set eshost "giasbm01.vsnl.net.in"
set esport 25
set esvrSock [socket $eshost $esport]
#fileevent $esvrSock readable [list read_sock $esvrSock]
fconfigure $esvrSock -buffering line
listbox .l -width 100
pack .l
.l insert end [gets $esvrSock]
set a "HELO vijay.com"
puts $esvrSock $a
.l insert end [gets $esvrSock]
set a "MAIL FROM:"
puts $esvrSock $a
.l insert end [gets $esvrSock]
set a "RCPT TO:"
puts $esvrSock $a
.l insert end [gets $esvrSock]
set a "DATA"
puts $esvrSock $a
.l insert end [gets $esvrSock]
set a "FROM: sonal100@giasbm01.vsnl.net.in"
puts $esvrSock $a
set a "DATE: 10 Jan 95 13:24 PST"
puts $esvrSock $a
set a "MESSAGE_ID: 420"
puts $esvrSock $a
set a "HELL"
puts $esvrSock $a
set a "Bye"
puts $esvrSock $a
set a "."
puts $esvrSock $a
.l insert end [gets $esvrSock]
set a "QUIT"
puts $esvrSock $a
.l insert end [gets $esvrSock]

s3.tcl
proc zzz { } {
set eshost [ .f.t get ]
set esport 80
set esvrSock [socket $eshost $esport]
.temp configure  -text $eshost
fileevent $esvrSock readable [list read_sock $esvrSock]
fconfigure $esvrSock -buffering line

set a "GET "
append a "/"
set a1 [ .ff.tt get ]
append a $a1
set aa "http://"
append aa $eshost
append aa "/"
append aa $a1
.temp configure  -text $aa
puts $esvrSock $a

}
proc read_sock { sock } {
set l [gets $sock]
.f1.t insert insert $l
.f1.t insert insert \n

}
frame .f 
label .f.l -text "Enter Name ............(www.neca.com)"
entry .f.t -width 45

frame .ff
label .ff.ll -text "Enter File Name ....(~vmis/java.html)"
entry .ff.tt -width 45

button .ff.b -text "Click" -command zzz

label .temp -text "Check"

frame .f1
text .f1.t -width 75 -height 20 -yscrollcommand { .f1.s set }
scrollbar .f1.s -command { .f1.t yview }
pack .f.l .f.t   -side left
pack .ff.ll .ff.tt .ff.b -side left
pack .f1.t .f1.s -fill y -side left
pack .f .ff -anchor w
pack .f1 -anchor w
pack .temp -anchor w -fill  x -side bottom

s4.tcl
proc read_sock { sock } {
set l [gets $sock]
.l insert end  $l
}

proc zzz { } {
set eshost "giasbm01.vsnl.net.in"
set esport 25
set esvrSock [socket $eshost $esport]
fileevent $esvrSock readable [list read_sock $esvrSock]
fconfigure $esvrSock -buffering line
set aa [.f3.t3 get 1.0 end ]
.f3.t3 insert insert $aa
.l insert end [gets $esvrSock]
set a "HELO vijay.com"
puts $esvrSock $a
.l insert end [gets $esvrSock]
set a "MAIL FROM:<"
append a [ .f1.e1 get ]
append a  ">"
puts $esvrSock $a
.l insert end [gets $esvrSock]
set a "RCPT TO:<"
append a [ .f2.e2 get ]
append a ">"
puts $esvrSock $a
.l insert end [gets $esvrSock]
set a "DATA"
puts $esvrSock $a
.l insert end [gets $esvrSock]
set a "FROM: "
append a [.f1.e1 get ]
puts $esvrSock $a
set a "DATE: 10 Jan 95 13:24 PST"
puts $esvrSock $a
set a "MESSAGE_ID: 420"
puts $esvrSock $a

set a $aa
puts $esvrSock $a
set a "."
puts $esvrSock $a
.l insert end [gets $esvrSock]
set a "QUIT"
puts $esvrSock $a
.l insert end [gets $esvrSock]
}


frame .f1
label .f1.l1 -text "Mail From......" 
entry .f1.e1  -width 40
pack  .f1.l1 .f1.e1 -side left

frame .f2
label .f2.l2 -text "Mail To......"
entry .f2.e2  -width 40
pack  .f2.l2 .f2.e2 -side left

frame .f3
label .f3.l3 -text "Message  :" 
text .f3.t3 -height 10 -width 50  -yscrollcommand { .f3.s3 set }
scrollbar .f3.s3 -command { .f3.t3 yview }
pack .f3.l3 -anchor w
pack .f3.t3 .f3.s3 -anchor w -side left -fill y
button .b -text "Send.." -command zzz

pack .f1 -anchor w
pack .f2 -anchor w
pack .f3 -anchor w
pack .b
listbox .l -width 60  
pack .l -anchor w


Have any suggestions, comments, ideas, cracked code, feedback. Feel free to get in touch with us.

Move back to the Vijay Mukhi's Technology Cornucopia Page to learn more about the other new Internet Technologies.


Vijay Mukhi's Computer Institute
VMCI, B-13, Everest Building, Tardeo, Bombay 400 034, India
E-mail:vmukhi@giasbm01.vsnl.net.in Tel : 91-22-496 4335 /6/7/8/9 Fax : 91-22-307 28 59
http://www.vijaymukhi.com