[comp.sys.mac.hypercard] Problem with MacTCP Toolkit V 1.0

SALTER-J@osu-20.ircc.ohio-state.edu (John Salter) (10/23/89)

I have a problem with MacTCP Toolkit V 1.0 with the Hypercard
interface when trying to connect (telnet) to one of our TCP/IP hosts.

The problem seems related to sending data using TCPSend.

Either, the Host is not receiving the characters as they are sent of
not interperting them correctly.

I was able to duplicate the behavior problem of the host
in a non-TCP/IP environment which I better understand.  Using a
asynchronous gateway to the same hosts and by changing the parity (even)
or the word length (7 bits) of the async software produce the same
problem. 

In the setup of the paramater block for TCPSend I didn't see anything
that was analogous to word length of parith setting in the TCP Parameter
block.  What are "validity bits"?

I tried setting and clearing the high bit of data in the send buffer
but that didn't help.

I have had successful connections to other hosts using the MacTCP
Toolkit.

The Host is a Bridge Box providing a gateway to an IBM Mainframe.  This
bridge box translates SNA-TCP/IP.  I am trying to learn more about
this box and the form of the TCP/IP data it expects.

By the way,  NCSA Telnet for the Mac talks to this Host just fine.

Is there a good source of documentation on TCP/IP communications programming?

I am new to Mac system programming.  Who do I address these questions?

To repeat my question, is there some parameter settings of data modification
in a program interface to MacTCP that is anologous to word length of parity
in the async arena?

Does anyone else have problems with MacTCP's TCPSend?

Any suggestions to help me solve my problem is greatly appreciated.

John Salter
Prgrammer/Analyst
Ohio State University Library
1858 Neil Avenue
Columbus, Ohio 43210
salter-j@osu-20@ohio-state.edu
(614) 292-6151

chesley@goofy.apple.com (Harry Chesley) (10/25/89)

In article <12536425863029@osu-20.ircc.ohio-state.edu> 
SALTER-J@osu-20.ircc.ohio-state.edu (John Salter) writes:
> I have a problem with MacTCP Toolkit V 1.0 with the Hypercard
> interface when trying to connect (telnet) to one of our TCP/IP hosts.

I know of two things that can keep a host from receiving MacTCP Toolkit 
sends. I think the first is probably your problem, but I'll mention them 
both just in case anyone else is having similar difficulties:

(1) The Toolkit supports TCP, not Telnet. Although Telnet doesn't add much 
on top of the reliable byte-stream of TCP, it does add some. It has an 
option negotiation protocol that sets up things like local or remote echo, 
terminal type, etc., etc. In theory, your application needs to be able to 
talk this protocol, at least to the extent of saying "no, I don't support 
that option" to any queries from the other side. Most hosts will talk to 
you even if you don't play the option game, but some hosts (I've run into 
it on our Cray and on a PDP-10) just refuse to talk until you answer their 
option negotiation queries. NCSA Telnet, being a Telnet program, supports 
the option protocol.

The protocol is described in the Telnet documentation. It's quite simple. 
However, if there's interest, I can try and modify the example stack to 
handle this negotiation and post the revised HyperTalk scripts here.

(2) Secondly, the MacTCP Toolkit XCMDs were designed to handle text, not 
random binary data. Because of this, and because of the way HyperCard 
stores strings internally, if you include a null in a string to be sent 
(i.e., do something like "abc" & numToChar(0) & "def"), only the 
characters before the null will be sent. Similarly, input is also 
truncated at nulls.

In article <12536425863029@osu-20.ircc.ohio-state.edu> 
SALTER-J@osu-20.ircc.ohio-state.edu (John Salter) writes:
> Is there a good source of documentation on TCP/IP communications 
programming?

There's the DDN Protocol Handbook, which is the definitive description of 
the protocols, available in three volumes from the DDN Network Information 
Center at SRI International, Menlo Park, CA.

In article <12536425863029@osu-20.ircc.ohio-state.edu> 
SALTER-J@osu-20.ircc.ohio-state.edu (John Salter) writes:
> I am new to Mac system programming.  Who do I address these questions?

This newsgroup is a pretty good place. Some Apple employees (like me) scan 
the group periodically and answer questions. But even better, there are a 
lot of people outside Apple with a lot of real-world experience whore more 
than happy to answer questions here.

sirkm@ssyx.ucsc.edu (Greg Anderson) (10/25/89)

In article <4877@internal.Apple.COM> chesley@goofy.apple.com (Harry Chesley) writes:
>In article <12536425863029@osu-20.ircc.ohio-state.edu> 
>SALTER-J@osu-20.ircc.ohio-state.edu (John Salter) writes:
>The protocol is described in the Telnet documentation. It's quite simple. 
>However, if there's interest, I can try and modify the example stack to 
>handle this negotiation and post the revised HyperTalk scripts here.

I need to be able to log into the telnet port--or use some other
method of reliably logging a user into a host unix machine--so I would
be interested in seeing those modifications.


  ___\    /___               Greg Anderson              ___\    /___ 
  \   \  /   /         Social Sciences Computing        \   \  /   /
   \  /\/\  /    University of California, Santa Cruz    \  /\/\  /
    \/    \/              sirkm@ssyx.ucsc.edu             \/    \/

chesley@goofy.apple.com (Harry Chesley) (10/27/89)

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