playing with sockets
Posted: Sun Feb 19, 2012 5:35 pm
Hello,
am trying to do a basic socket client for teaching purposes to show how http protocol works: send a request to host, get and print response.
Based on some forum example I did this, sending a string like GET /index.php HTTP/1.1
What's wrong?
Another simple question when run code using browse tool, program never restarts, continue in the same state left in previous run, why?
Thanks
Jose
am trying to do a basic socket client for teaching purposes to show how http protocol works: send a request to host, get and print response.
Based on some forum example I did this, sending a string like GET /index.php HTTP/1.1
Code: Select all
local testServer
put "tontos.com:80" into testServer
command writeit
write field "Message" & format("\r\n") to socket testServer
put empty into field "Message"
end writeit
command connectIt
put "entering into connectIt" & cr after field "logField"
if testServer is among the lines of the opensockets then
close socket testServer
set the label of button "Connect" to "Connect"
else
open socket to testServer
set the label of button "Connect" to "Disconnect"
if the Result <> "" then
put "result:" && the result
else
readLoop
end if
end if
end connectIt
command readLoop
put "entering into readLoop2" & cr after field "logField"
if testServer is among the lines of the opensockets then
put "readLoop in opensockets 2" & cr after field "logField"
read from socket testServer until empty
put it after field "logField" --this never returns anything
send "readLoop" to me in 50 milliseconds
end if
end readLoop
Another simple question when run code using browse tool, program never restarts, continue in the same state left in previous run, why?
Thanks
Jose