blob: 561284b4341142a91cfba19cb03132705072cc14 [file] [log] [blame]
Guido van Rossum470be141995-03-17 16:07:09 +00001\section{Built-in Module \sectcode{mactcp}}
Jack Jansenb721ef11995-03-01 14:54:30 +00002\bimodindex{mactcp}
Guido van Rossum470be141995-03-17 16:07:09 +00003
Jack Jansenb721ef11995-03-01 14:54:30 +00004\renewcommand{\indexsubitem}{(in module mactcp)}
5
6This module provides an interface to the Macintosh TCP/IP driver
Guido van Rossum6bb1adc1995-03-13 10:03:32 +00007MacTCP\@. There is an accompanying module \code{macdnr} which provides an
Jack Jansenb721ef11995-03-01 14:54:30 +00008interface to the name-server (allowing you to translate hostnames to
Guido van Rossum6bb1adc1995-03-13 10:03:32 +00009ip-addresses), a module \code{MACTCP} which has symbolic names for
10constants constants used by MacTCP and a wrapper module \code{socket}
11which mimics the \UNIX{} socket interface (as far as possible).
Jack Jansenb721ef11995-03-01 14:54:30 +000012
13A complete description of the MacTCP interface can be found in the
14Apple MacTCP API documentation.
15
16\begin{funcdesc}{MTU}{}
17Return the Maximum Transmit Unit (the packet size) of the network
18interface.
19\end{funcdesc}
20
21\begin{funcdesc}{IPAddr}{}
22Return the 32-bit integer IP address of the network interface.
23\end{funcdesc}
24
25\begin{funcdesc}{NetMask}{}
26Return the 32-bit integer network mask of the interface.
27\end{funcdesc}
28
29\begin{funcdesc}{TCPCreate}{size}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000030Create a TCP Stream object. \var{size} is the size of the receive
Jack Jansenb721ef11995-03-01 14:54:30 +000031buffer, \code{4096} is suggested by various sources.
32\end{funcdesc}
33
34\begin{funcdesc}{UDPCreate}{size, port}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000035Create a UDP stream object. \var{size} is the size of the receive
Jack Jansenb721ef11995-03-01 14:54:30 +000036buffer (and, hence, the size of the biggest datagram you can receive
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000037on this port). \var{port} is the UDP port number you want to receive
Jack Jansenb721ef11995-03-01 14:54:30 +000038datagrams on, a value of zero will make MacTCP select a free port.
39\end{funcdesc}
40
Guido van Rossum470be141995-03-17 16:07:09 +000041\subsection{TCP Stream Objects}
42
43\renewcommand{\indexsubitem}{(TCP stream attribute)}
Jack Jansenb721ef11995-03-01 14:54:30 +000044
45\begin{datadesc}{asr}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000046When set to a value different than \code{None} this should point to a
47function with two integer parameters:\ an event code and a detail. This
Jack Jansenb721ef11995-03-01 14:54:30 +000048function will be called upon network-generated events such as urgent
49data arrival. In addition, it is called with eventcode
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000050\code{MACTCP.PassiveOpenDone} when a \code{PassiveOpen} completes. This
51is a Python addition to the MacTCP semantics.
52It is safe to do further calls from the \code{asr}.
Jack Jansenb721ef11995-03-01 14:54:30 +000053\end{datadesc}
54
Guido van Rossum470be141995-03-17 16:07:09 +000055\renewcommand{\indexsubitem}{(TCP stream method)}
56
Jack Jansenb721ef11995-03-01 14:54:30 +000057\begin{funcdesc}{PassiveOpen}{port}
58Wait for an incoming connection on TCP port \var{port} (zero makes the
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000059system pick a free port). The call returns immediately, and you should
Jack Jansenb721ef11995-03-01 14:54:30 +000060use \var{wait} to wait for completion. You should not issue any method
61calls other than
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000062\code{wait}, \code{isdone} or \code{GetSockName} before the call
Jack Jansenb721ef11995-03-01 14:54:30 +000063completes.
64\end{funcdesc}
65
66\begin{funcdesc}{wait}{}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000067Wait for \code{PassiveOpen} to complete.
Jack Jansenb721ef11995-03-01 14:54:30 +000068\end{funcdesc}
69
70\begin{funcdesc}{isdone}{}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000071Return 1 if a \code{PassiveOpen} has completed.
Jack Jansenb721ef11995-03-01 14:54:30 +000072\end{funcdesc}
73
74\begin{funcdesc}{GetSockName}{}
75Return the TCP address of this side of a connection as a 2-tuple
76\code{(host, port)}, both integers.
77\end{funcdesc}
78
79\begin{funcdesc}{ActiveOpen}{lport\, host\, rport}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000080Open an outgoing connection to TCP address \code{(\var{host}, \var{rport})}. Use
Jack Jansenb721ef11995-03-01 14:54:30 +000081local port \var{lport} (zero makes the system pick a free port). This
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000082call blocks until the connection has been established.
Jack Jansenb721ef11995-03-01 14:54:30 +000083\end{funcdesc}
84
85\begin{funcdesc}{Send}{buf\, push\, urgent}
86Send data \var{buf} over the connection. \var{Push} and \var{urgent}
87are flags as specified by the TCP standard.
88\end{funcdesc}
89
90\begin{funcdesc}{Rcv}{timeout}
91Receive data. The call returns when \var{timeout} seconds have passed
92or when (according to the MacTCP documentation) ``a reasonable amount
93of data has been received''. The return value is a 3-tuple
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000094\code{(\var{data}, \var{urgent}, \var{mark})}. If urgent data is outstanding \code{Rcv}
Jack Jansenb721ef11995-03-01 14:54:30 +000095will always return that before looking at any normal data. The first
96call returning urgent data will have the \var{urgent} flag set, the
97last will have the \var{mark} flag set.
98\end{funcdesc}
99
100\begin{funcdesc}{Close}{}
101Tell MacTCP that no more data will be transmitted on this
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000102connection. The call returns when all data has been acknowledged by
Jack Jansenb721ef11995-03-01 14:54:30 +0000103the receiving side.
104\end{funcdesc}
105
106\begin{funcdesc}{Abort}{}
107Forcibly close both sides of a connection, ignoring outstanding data.
108\end{funcdesc}
109
110\begin{funcdesc}{Status}{}
Guido van Rossum470be141995-03-17 16:07:09 +0000111Return a TCP status object for this stream giving the current status
112(see below).
Jack Jansenb721ef11995-03-01 14:54:30 +0000113\end{funcdesc}
114
Guido van Rossum470be141995-03-17 16:07:09 +0000115\subsection{TCP Status Objects}
Jack Jansenb721ef11995-03-01 14:54:30 +0000116This object has no methods, only some members holding information on
117the connection. A complete description of all fields in this objects
118can be found in the Apple documentation. The most interesting ones are:
119
Guido van Rossum470be141995-03-17 16:07:09 +0000120\renewcommand{\indexsubitem}{(TCP status attribute)}
121
Jack Jansenb721ef11995-03-01 14:54:30 +0000122\begin{datadesc}{localHost}
123\dataline{localPort}
124\dataline{remoteHost}
125\dataline{remotePort}
126The integer IP-addresses and port numbers of both endpoints of the
127connection.
128\end{datadesc}
129
130\begin{datadesc}{sendWindow}
131The current window size.
132\end{datadesc}
133
134\begin{datadesc}{amtUnackedData}
135The number of bytes sent but not yet acknowledged. \code{sendWindow -
136amtUnackedData} is what you can pass to \code{Send} without blocking.
137\end{datadesc}
138
139\begin{datadesc}{amtUnreadData}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000140The number of bytes received but not yet read (what you can \code{Recv}
Jack Jansenb721ef11995-03-01 14:54:30 +0000141without blocking).
142\end{datadesc}
143
144
145
Guido van Rossum470be141995-03-17 16:07:09 +0000146\subsection{UDP Stream Objects}
Jack Jansenb721ef11995-03-01 14:54:30 +0000147Note that, unlike the name suggests, there is nothing stream-like
148about UDP.
149
Guido van Rossum470be141995-03-17 16:07:09 +0000150\renewcommand{\indexsubitem}{(UDP stream attribute)}
Jack Jansenb721ef11995-03-01 14:54:30 +0000151
152\begin{datadesc}{asr}
153The asynchronous service routine to be called on events such as
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000154datagram arrival without outstanding \code{Read} call. The \code{asr} has a
Jack Jansenb721ef11995-03-01 14:54:30 +0000155single argument, the event code.
156\end{datadesc}
157
158\begin{datadesc}{port}
159A read-only member giving the port number of this UDP stream.
160\end{datadesc}
161
Guido van Rossum470be141995-03-17 16:07:09 +0000162\renewcommand{\indexsubitem}{(UDP stream method)}
163
Jack Jansenb721ef11995-03-01 14:54:30 +0000164\begin{funcdesc}{Read}{timeout}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000165Read a datagram, waiting at most \var{timeout} seconds ($-1$ is
Guido van Rossum470be141995-03-17 16:07:09 +0000166infinite). Return the data.
Jack Jansenb721ef11995-03-01 14:54:30 +0000167\end{funcdesc}
168
169\begin{funcdesc}{Write}{host\, port\, buf}
170Send \var{buf} as a datagram to IP-address \var{host}, port
171\var{port}.
172\end{funcdesc}