How to mimic telnet session

Dar Scott dsc at swcp.com
Mon Dec 29 12:46:25 EST 2003


On Monday, December 29, 2003, at 09:50 AM, RGould8 at aol.com wrote:

> Can anyone tell me what I'm missing in my code?
> When I click the button, it seems to send successfully, but I get 
> nothing
> back...

The main problem is the read callback at the end, but I'll comment on 
other things, too.

Basic structure looks good, though you seem to be mixing callback style 
with non-callback style.  Perhaps you are planning on a callback style 
eventually.

You might want to put your resulting reporting lines after open and 
close, too.


>
>
> on mouseUp
> open socket "dins.gte.net:7777"
> write "cmd=getAccessType"  & CRLF to socket  "dins.gte.net:7777" with 
> message
> "callbackmsg"

-- You can get by without 'with message "callbackmsg"' for now.  
-- Put this here in any case:
put "callback (the result) = "  & the result & LF after msg
-- If you leave in the callback, it will not run until after the close 
unless you
-- change the wait below to allow messages.

> wait 3  seconds
> read from socket "dins.gte.net:7777" for 80 with message  "gotData"

-- During testing you might want to change this to 'until empty' 
-- (meaning get all in buffers) instead of 'for 80'.
-- Check for an error at this point, too:
put "read (the result) = " & the result & LF after msg

-- You can drop the 'with message "gotData"' for now and do this:
put "databack (the data) = " & it & LF after msg


> close socket "dins.gte.et:7777"
> end  mouseUp
>
>
> on callbackmsg data
> put "callback (the result) = "  & the result
-- No.  I don't know of any meaning for result() here.
put "callback" & LF after msg
> end callbackmsg
>
> on socketError
> answer "got  an error"
--Add the error parameter to your answer.
-- You might want to change this to 'put ... & LF after msg'.
> end socketError
-- Good.  You might want to also include socketClosed and the timeout 
callbacks.
-- (On OS X, socketClosed will occur any time it is closed.)
>
> on gotData
  on gotData socketID data
> put "databack (the  result) = " & the result
-- No.  This is the main problem.
put "databack (the data) = " & data & LF after msg
> end  gotData

I hope this isn't too much at once.  Let us know.

Dar Scott



More information about the use-livecode mailing list