1998-04-04 03:23:21 -04:00
|
|
|
\section{Built-in Module \module{mactcp}}
|
1997-07-17 13:34:52 -03:00
|
|
|
\label{module-mactcp}
|
1995-03-01 10:54:30 -04:00
|
|
|
\bimodindex{mactcp}
|
1995-03-17 12:07:09 -04:00
|
|
|
|
1995-03-01 10:54:30 -04:00
|
|
|
|
1998-04-03 03:16:46 -04:00
|
|
|
This module provides an interface to the Macintosh TCP/IP driver%
|
|
|
|
\index{MacTCP} MacTCP\@. There is an accompanying module,
|
|
|
|
\module{macdnr}\refbimodindex{macdnr}, which provides an interface to
|
|
|
|
the name-server (allowing you to translate hostnames to IP addresses),
|
|
|
|
a module \module{MACTCPconst}\refstmodindex{MACTCPconst} which has
|
|
|
|
symbolic names for constants constants used by MacTCP. Since the
|
|
|
|
built-in module \module{socket} is also available on the Macintosh it
|
|
|
|
is usually easier to use sockets instead of the Macintosh-specific
|
|
|
|
MacTCP API.
|
1995-03-01 10:54:30 -04:00
|
|
|
|
|
|
|
A complete description of the MacTCP interface can be found in the
|
|
|
|
Apple MacTCP API documentation.
|
|
|
|
|
|
|
|
\begin{funcdesc}{MTU}{}
|
|
|
|
Return the Maximum Transmit Unit (the packet size) of the network
|
1998-04-03 03:16:46 -04:00
|
|
|
interface.\index{Maximum Transmit Unit}
|
1995-03-01 10:54:30 -04:00
|
|
|
\end{funcdesc}
|
|
|
|
|
|
|
|
\begin{funcdesc}{IPAddr}{}
|
|
|
|
Return the 32-bit integer IP address of the network interface.
|
|
|
|
\end{funcdesc}
|
|
|
|
|
|
|
|
\begin{funcdesc}{NetMask}{}
|
|
|
|
Return the 32-bit integer network mask of the interface.
|
|
|
|
\end{funcdesc}
|
|
|
|
|
|
|
|
\begin{funcdesc}{TCPCreate}{size}
|
1995-03-13 06:03:32 -04:00
|
|
|
Create a TCP Stream object. \var{size} is the size of the receive
|
1995-03-01 10:54:30 -04:00
|
|
|
buffer, \code{4096} is suggested by various sources.
|
|
|
|
\end{funcdesc}
|
|
|
|
|
|
|
|
\begin{funcdesc}{UDPCreate}{size, port}
|
1998-04-03 03:16:46 -04:00
|
|
|
Create a UDP Stream object. \var{size} is the size of the receive
|
1995-03-01 10:54:30 -04:00
|
|
|
buffer (and, hence, the size of the biggest datagram you can receive
|
1995-03-13 06:03:32 -04:00
|
|
|
on this port). \var{port} is the UDP port number you want to receive
|
1995-03-01 10:54:30 -04:00
|
|
|
datagrams on, a value of zero will make MacTCP select a free port.
|
|
|
|
\end{funcdesc}
|
|
|
|
|
1995-03-17 12:07:09 -04:00
|
|
|
|
1998-04-03 03:16:46 -04:00
|
|
|
\subsection{TCP Stream Objects}
|
1995-03-01 10:54:30 -04:00
|
|
|
|
1998-04-03 03:16:46 -04:00
|
|
|
\begin{memberdesc}[TCP Stream]{asr}
|
|
|
|
\index{asynchronous service routine}
|
|
|
|
\index{service routine, asynchronous}
|
|
|
|
When set to a value different than \code{None} this should refer to a
|
1995-03-13 06:03:32 -04:00
|
|
|
function with two integer parameters:\ an event code and a detail. This
|
1995-03-01 10:54:30 -04:00
|
|
|
function will be called upon network-generated events such as urgent
|
1998-04-03 03:16:46 -04:00
|
|
|
data arrival. Macintosh documentation calls this the
|
|
|
|
\dfn{asynchronous service routine}. In addition, it is called with
|
|
|
|
eventcode \code{MACTCP.PassiveOpenDone} when a \code{PassiveOpen}
|
|
|
|
completes. This is a Python addition to the MacTCP semantics.
|
|
|
|
It is safe to do further calls from \var{asr}.
|
|
|
|
\end{memberdesc}
|
1995-03-01 10:54:30 -04:00
|
|
|
|
1995-03-17 12:07:09 -04:00
|
|
|
|
1998-04-03 03:16:46 -04:00
|
|
|
\begin{methoddesc}[TCP Stream]{PassiveOpen}{port}
|
1995-03-01 10:54:30 -04:00
|
|
|
Wait for an incoming connection on TCP port \var{port} (zero makes the
|
1995-03-13 06:03:32 -04:00
|
|
|
system pick a free port). The call returns immediately, and you should
|
1998-04-03 03:16:46 -04:00
|
|
|
use \method{wait()} to wait for completion. You should not issue any method
|
|
|
|
calls other than \method{wait()}, \method{isdone()} or
|
|
|
|
\method{GetSockName()} before the call completes.
|
|
|
|
\end{methoddesc}
|
1995-03-01 10:54:30 -04:00
|
|
|
|
1998-04-03 03:16:46 -04:00
|
|
|
\begin{methoddesc}[TCP Stream]{wait}{}
|
1995-03-13 06:03:32 -04:00
|
|
|
Wait for \code{PassiveOpen} to complete.
|
1998-04-03 03:16:46 -04:00
|
|
|
\end{methoddesc}
|
1995-03-01 10:54:30 -04:00
|
|
|
|
1998-04-03 03:16:46 -04:00
|
|
|
\begin{methoddesc}[TCP Stream]{isdone}{}
|
|
|
|
Return \code{1} if a \code{PassiveOpen} has completed.
|
|
|
|
\end{methoddesc}
|
1995-03-01 10:54:30 -04:00
|
|
|
|
1998-04-03 03:16:46 -04:00
|
|
|
\begin{methoddesc}[TCP Stream]{GetSockName}{}
|
1995-03-01 10:54:30 -04:00
|
|
|
Return the TCP address of this side of a connection as a 2-tuple
|
1998-04-03 03:16:46 -04:00
|
|
|
\code{(\var{host}, \var{port})}, both integers.
|
|
|
|
\end{methoddesc}
|
1995-03-01 10:54:30 -04:00
|
|
|
|
1998-04-03 03:16:46 -04:00
|
|
|
\begin{methoddesc}[TCP Stream]{ActiveOpen}{lport, host, rport}
|
|
|
|
Open an outgoing connection to TCP address \code{(\var{host},
|
|
|
|
\var{rport})}. Use
|
1995-03-01 10:54:30 -04:00
|
|
|
local port \var{lport} (zero makes the system pick a free port). This
|
1995-03-13 06:03:32 -04:00
|
|
|
call blocks until the connection has been established.
|
1998-04-03 03:16:46 -04:00
|
|
|
\end{methoddesc}
|
1995-03-01 10:54:30 -04:00
|
|
|
|
1998-04-03 03:16:46 -04:00
|
|
|
\begin{methoddesc}[TCP Stream]{Send}{buf, push, urgent}
|
|
|
|
Send data \var{buf} over the connection. \var{push} and \var{urgent}
|
1995-03-01 10:54:30 -04:00
|
|
|
are flags as specified by the TCP standard.
|
1998-04-03 03:16:46 -04:00
|
|
|
\end{methoddesc}
|
1995-03-01 10:54:30 -04:00
|
|
|
|
1998-04-03 03:16:46 -04:00
|
|
|
\begin{methoddesc}[TCP Stream]{Rcv}{timeout}
|
1995-03-01 10:54:30 -04:00
|
|
|
Receive data. The call returns when \var{timeout} seconds have passed
|
|
|
|
or when (according to the MacTCP documentation) ``a reasonable amount
|
|
|
|
of data has been received''. The return value is a 3-tuple
|
1998-04-03 03:16:46 -04:00
|
|
|
\code{(\var{data}, \var{urgent}, \var{mark})}. If urgent data is
|
|
|
|
outstanding \code{Rcv} will always return that before looking at any
|
|
|
|
normal data. The first call returning urgent data will have the
|
|
|
|
\var{urgent} flag set, the last will have the \var{mark} flag set.
|
|
|
|
\end{methoddesc}
|
1995-03-01 10:54:30 -04:00
|
|
|
|
1998-04-03 03:16:46 -04:00
|
|
|
\begin{methoddesc}[TCP Stream]{Close}{}
|
1995-03-01 10:54:30 -04:00
|
|
|
Tell MacTCP that no more data will be transmitted on this
|
1995-03-13 06:03:32 -04:00
|
|
|
connection. The call returns when all data has been acknowledged by
|
1995-03-01 10:54:30 -04:00
|
|
|
the receiving side.
|
1998-04-03 03:16:46 -04:00
|
|
|
\end{methoddesc}
|
1995-03-01 10:54:30 -04:00
|
|
|
|
1998-04-03 03:16:46 -04:00
|
|
|
\begin{methoddesc}[TCP Stream]{Abort}{}
|
1995-03-01 10:54:30 -04:00
|
|
|
Forcibly close both sides of a connection, ignoring outstanding data.
|
1998-04-03 03:16:46 -04:00
|
|
|
\end{methoddesc}
|
1995-03-01 10:54:30 -04:00
|
|
|
|
1998-04-03 03:16:46 -04:00
|
|
|
\begin{methoddesc}[TCP Stream]{Status}{}
|
1995-03-17 12:07:09 -04:00
|
|
|
Return a TCP status object for this stream giving the current status
|
|
|
|
(see below).
|
1998-04-03 03:16:46 -04:00
|
|
|
\end{methoddesc}
|
|
|
|
|
1995-03-01 10:54:30 -04:00
|
|
|
|
1995-03-17 12:07:09 -04:00
|
|
|
\subsection{TCP Status Objects}
|
1998-04-03 03:16:46 -04:00
|
|
|
|
1995-03-01 10:54:30 -04:00
|
|
|
This object has no methods, only some members holding information on
|
|
|
|
the connection. A complete description of all fields in this objects
|
|
|
|
can be found in the Apple documentation. The most interesting ones are:
|
|
|
|
|
1998-04-03 03:16:46 -04:00
|
|
|
\begin{memberdesc}[TCP Status]{localHost}
|
|
|
|
\memberline{localPort}
|
|
|
|
\memberline{remoteHost}
|
|
|
|
\memberline{remotePort}
|
1995-03-01 10:54:30 -04:00
|
|
|
The integer IP-addresses and port numbers of both endpoints of the
|
|
|
|
connection.
|
1998-04-03 03:16:46 -04:00
|
|
|
\end{memberdesc}
|
1995-03-01 10:54:30 -04:00
|
|
|
|
1998-04-03 03:16:46 -04:00
|
|
|
\begin{memberdesc}[TCP Status]{sendWindow}
|
1995-03-01 10:54:30 -04:00
|
|
|
The current window size.
|
1998-04-03 03:16:46 -04:00
|
|
|
\end{memberdesc}
|
1995-03-01 10:54:30 -04:00
|
|
|
|
1998-04-03 03:16:46 -04:00
|
|
|
\begin{memberdesc}[TCP Status]{amtUnackedData}
|
1995-03-01 10:54:30 -04:00
|
|
|
The number of bytes sent but not yet acknowledged. \code{sendWindow -
|
1998-04-03 03:16:46 -04:00
|
|
|
amtUnackedData} is what you can pass to \method{Send()} without
|
|
|
|
blocking.
|
|
|
|
\end{memberdesc}
|
1995-03-01 10:54:30 -04:00
|
|
|
|
1998-04-03 03:16:46 -04:00
|
|
|
\begin{memberdesc}[TCP Status]{amtUnreadData}
|
|
|
|
The number of bytes received but not yet read (what you can
|
|
|
|
\method{Recv()} without blocking).
|
|
|
|
\end{memberdesc}
|
1995-03-01 10:54:30 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
1995-03-17 12:07:09 -04:00
|
|
|
\subsection{UDP Stream Objects}
|
1998-04-03 03:16:46 -04:00
|
|
|
|
1995-03-01 10:54:30 -04:00
|
|
|
Note that, unlike the name suggests, there is nothing stream-like
|
|
|
|
about UDP.
|
|
|
|
|
|
|
|
|
1998-04-03 03:16:46 -04:00
|
|
|
\begin{memberdesc}[UDP Stream]{asr}
|
|
|
|
\index{asynchronous service routine}
|
|
|
|
\index{service routine, asynchronous}
|
1995-03-01 10:54:30 -04:00
|
|
|
The asynchronous service routine to be called on events such as
|
1998-04-03 03:16:46 -04:00
|
|
|
datagram arrival without outstanding \code{Read} call. The \var{asr}
|
|
|
|
has a single argument, the event code.
|
|
|
|
\end{memberdesc}
|
1995-03-01 10:54:30 -04:00
|
|
|
|
1998-04-03 03:16:46 -04:00
|
|
|
\begin{memberdesc}[UDP Stream]{port}
|
|
|
|
A read-only member giving the port number of this UDP Stream.
|
|
|
|
\end{memberdesc}
|
1995-03-01 10:54:30 -04:00
|
|
|
|
1995-03-17 12:07:09 -04:00
|
|
|
|
1998-04-03 03:16:46 -04:00
|
|
|
\begin{methoddesc}[UDP Stream]{Read}{timeout}
|
1997-11-24 21:00:40 -04:00
|
|
|
Read a datagram, waiting at most \var{timeout} seconds (-1 is
|
1995-03-17 12:07:09 -04:00
|
|
|
infinite). Return the data.
|
1998-04-03 03:16:46 -04:00
|
|
|
\end{methoddesc}
|
1995-03-01 10:54:30 -04:00
|
|
|
|
1998-04-03 03:16:46 -04:00
|
|
|
\begin{methoddesc}[UDP Stream]{Write}{host, port, buf}
|
1995-03-01 10:54:30 -04:00
|
|
|
Send \var{buf} as a datagram to IP-address \var{host}, port
|
|
|
|
\var{port}.
|
1998-04-03 03:16:46 -04:00
|
|
|
\end{methoddesc}
|