Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!apple!goofy.apple.com!chesley From: chesley@goofy.apple.com (Harry Chesley) Newsgroups: comp.sys.mac.hypercard Subject: Re: Problem with MacTCP Toolkit V 1.0 Message-ID: <4913@internal.Apple.COM> Date: 26 Oct 89 17:42:20 GMT Sender: usenet@Apple.COM Organization: Apple Computer, Inc. Lines: 76 References:<12536425863029@osu-20.ircc.ohio-state.edu> <4877@internal.Apple.COM> Here is the code to make the HyperCard MacTCP Toolkit example stack handle Telnet option negotiation. All it does is reject all options, both offers and requests. Therefore, it is enough to get the example stack to work with a host that insists on doing option negotiation, but does not really have a deep understanding of options. I've tried this code out with our Cray, which insists on option negotiation, but it hasn't been tested real thoroughly other than that. The following two methods replace the "on idle" method in the background script of the main card in the example stack: on idle global connectionID -- Make sure we've got an open connection. if connectionID is empty then put "no connection" into field "state" exit idle end if -- And the connection is established. get TCPState(connectionID) put it into field "state" if it is not "established" then exit idle -- Get a line (or whatever you can get in a sixth of a second). put TCPRecvUpTo(connectionID,return,10,empty) into newInput if newInput is not empty then -- Check for telnet commands. if numToChar(255) is in newInput then telnetCommands newInput -- Figure out how many lines the field will fit. get rect of field "screen" get (item 4 of it) - (item 2 of it) put (it div (the textHeight of field "screen"))-1 into linesAvail -- Get the new field contents. get field "screen" & newInput -- Cut to fit. put the number of lines in it into linesThere if linesThere > linesAvail then delete line 1 to (linesThere-linesAvail) of it end if -- Display it. put it into field "screen" end if end idle on telnetCommands s global connectionID -- Go through all the new characters, handling telnet options -- Note: This code assumes that both the DO/DON'T/WILL/WON'T -- and the accompanying option specification are in s. If they -- get split across a receive, this will break. However, we -- wait long enough, and they should arrive in the same packet -- anyway that this should not be a problem. repeat while s is not empty -- Get the character and remove it from s. get charToNum(char 1 of s) delete char 1 of s -- Check for command lead-in character. if it is 255 then -- Get the command itself. get charToNum(char 1 of s) delete char 1 of s -- Check for WILL/WON'T/DO/DON'T. if (it > 250) and (it < 256) then -- If it's DO/DON'T, then answer WON'T. if it > 252 then get 252 -- if it's WILL/WON'T, then answer DON'T. else get 254 -- Send the negotiation response (getting the option char). TCPSend connectionID,numToChar(255) & numToChar(it) & B (char 1 of s) delete char 1 of s end if end if end repeat end telnetCommands