blob: 6c5a78bf60b878c4cd2703eeff0c3ceee4fff2d2 [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}
Guido van Rossum96628a91995-04-10 11:34:00 +000011which mimics the \UNIX{} socket interface (as far as possible). It may
12not be available in all Mac Python versions.
Jack Jansenb721ef11995-03-01 14:54:30 +000013
14A complete description of the MacTCP interface can be found in the
15Apple MacTCP API documentation.
16
17\begin{funcdesc}{MTU}{}
18Return the Maximum Transmit Unit (the packet size) of the network
19interface.
20\end{funcdesc}
21
22\begin{funcdesc}{IPAddr}{}
23Return the 32-bit integer IP address of the network interface.
24\end{funcdesc}
25
26\begin{funcdesc}{NetMask}{}
27Return the 32-bit integer network mask of the interface.
28\end{funcdesc}
29
30\begin{funcdesc}{TCPCreate}{size}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000031Create a TCP Stream object. \var{size} is the size of the receive
Jack Jansenb721ef11995-03-01 14:54:30 +000032buffer, \code{4096} is suggested by various sources.
33\end{funcdesc}
34
35\begin{funcdesc}{UDPCreate}{size, port}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000036Create a UDP stream object. \var{size} is the size of the receive
Jack Jansenb721ef11995-03-01 14:54:30 +000037buffer (and, hence, the size of the biggest datagram you can receive
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000038on this port). \var{port} is the UDP port number you want to receive
Jack Jansenb721ef11995-03-01 14:54:30 +000039datagrams on, a value of zero will make MacTCP select a free port.
40\end{funcdesc}
41
Guido van Rossum470be141995-03-17 16:07:09 +000042\subsection{TCP Stream Objects}
43
44\renewcommand{\indexsubitem}{(TCP stream attribute)}
Jack Jansenb721ef11995-03-01 14:54:30 +000045
46\begin{datadesc}{asr}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000047When set to a value different than \code{None} this should point to a
48function with two integer parameters:\ an event code and a detail. This
Jack Jansenb721ef11995-03-01 14:54:30 +000049function will be called upon network-generated events such as urgent
50data arrival. In addition, it is called with eventcode
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000051\code{MACTCP.PassiveOpenDone} when a \code{PassiveOpen} completes. This
52is a Python addition to the MacTCP semantics.
53It is safe to do further calls from the \code{asr}.
Jack Jansenb721ef11995-03-01 14:54:30 +000054\end{datadesc}
55
Guido van Rossum470be141995-03-17 16:07:09 +000056\renewcommand{\indexsubitem}{(TCP stream method)}
57
Jack Jansenb721ef11995-03-01 14:54:30 +000058\begin{funcdesc}{PassiveOpen}{port}
59Wait for an incoming connection on TCP port \var{port} (zero makes the
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000060system pick a free port). The call returns immediately, and you should
Jack Jansenb721ef11995-03-01 14:54:30 +000061use \var{wait} to wait for completion. You should not issue any method
62calls other than
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000063\code{wait}, \code{isdone} or \code{GetSockName} before the call
Jack Jansenb721ef11995-03-01 14:54:30 +000064completes.
65\end{funcdesc}
66
67\begin{funcdesc}{wait}{}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000068Wait for \code{PassiveOpen} to complete.
Jack Jansenb721ef11995-03-01 14:54:30 +000069\end{funcdesc}
70
71\begin{funcdesc}{isdone}{}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000072Return 1 if a \code{PassiveOpen} has completed.
Jack Jansenb721ef11995-03-01 14:54:30 +000073\end{funcdesc}
74
75\begin{funcdesc}{GetSockName}{}
76Return the TCP address of this side of a connection as a 2-tuple
77\code{(host, port)}, both integers.
78\end{funcdesc}
79
80\begin{funcdesc}{ActiveOpen}{lport\, host\, rport}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000081Open an outgoing connection to TCP address \code{(\var{host}, \var{rport})}. Use
Jack Jansenb721ef11995-03-01 14:54:30 +000082local port \var{lport} (zero makes the system pick a free port). This
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000083call blocks until the connection has been established.
Jack Jansenb721ef11995-03-01 14:54:30 +000084\end{funcdesc}
85
86\begin{funcdesc}{Send}{buf\, push\, urgent}
87Send data \var{buf} over the connection. \var{Push} and \var{urgent}
88are flags as specified by the TCP standard.
89\end{funcdesc}
90
91\begin{funcdesc}{Rcv}{timeout}
92Receive data. The call returns when \var{timeout} seconds have passed
93or when (according to the MacTCP documentation) ``a reasonable amount
94of data has been received''. The return value is a 3-tuple
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000095\code{(\var{data}, \var{urgent}, \var{mark})}. If urgent data is outstanding \code{Rcv}
Jack Jansenb721ef11995-03-01 14:54:30 +000096will always return that before looking at any normal data. The first
97call returning urgent data will have the \var{urgent} flag set, the
98last will have the \var{mark} flag set.
99\end{funcdesc}
100
101\begin{funcdesc}{Close}{}
102Tell MacTCP that no more data will be transmitted on this
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000103connection. The call returns when all data has been acknowledged by
Jack Jansenb721ef11995-03-01 14:54:30 +0000104the receiving side.
105\end{funcdesc}
106
107\begin{funcdesc}{Abort}{}
108Forcibly close both sides of a connection, ignoring outstanding data.
109\end{funcdesc}
110
111\begin{funcdesc}{Status}{}
Guido van Rossum470be141995-03-17 16:07:09 +0000112Return a TCP status object for this stream giving the current status
113(see below).
Jack Jansenb721ef11995-03-01 14:54:30 +0000114\end{funcdesc}
115
Guido van Rossum470be141995-03-17 16:07:09 +0000116\subsection{TCP Status Objects}
Jack Jansenb721ef11995-03-01 14:54:30 +0000117This object has no methods, only some members holding information on
118the connection. A complete description of all fields in this objects
119can be found in the Apple documentation. The most interesting ones are:
120
Guido van Rossum470be141995-03-17 16:07:09 +0000121\renewcommand{\indexsubitem}{(TCP status attribute)}
122
Jack Jansenb721ef11995-03-01 14:54:30 +0000123\begin{datadesc}{localHost}
124\dataline{localPort}
125\dataline{remoteHost}
126\dataline{remotePort}
127The integer IP-addresses and port numbers of both endpoints of the
128connection.
129\end{datadesc}
130
131\begin{datadesc}{sendWindow}
132The current window size.
133\end{datadesc}
134
135\begin{datadesc}{amtUnackedData}
136The number of bytes sent but not yet acknowledged. \code{sendWindow -
137amtUnackedData} is what you can pass to \code{Send} without blocking.
138\end{datadesc}
139
140\begin{datadesc}{amtUnreadData}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000141The number of bytes received but not yet read (what you can \code{Recv}
Jack Jansenb721ef11995-03-01 14:54:30 +0000142without blocking).
143\end{datadesc}
144
145
146
Guido van Rossum470be141995-03-17 16:07:09 +0000147\subsection{UDP Stream Objects}
Jack Jansenb721ef11995-03-01 14:54:30 +0000148Note that, unlike the name suggests, there is nothing stream-like
149about UDP.
150
Guido van Rossum470be141995-03-17 16:07:09 +0000151\renewcommand{\indexsubitem}{(UDP stream attribute)}
Jack Jansenb721ef11995-03-01 14:54:30 +0000152
153\begin{datadesc}{asr}
154The asynchronous service routine to be called on events such as
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000155datagram arrival without outstanding \code{Read} call. The \code{asr} has a
Jack Jansenb721ef11995-03-01 14:54:30 +0000156single argument, the event code.
157\end{datadesc}
158
159\begin{datadesc}{port}
160A read-only member giving the port number of this UDP stream.
161\end{datadesc}
162
Guido van Rossum470be141995-03-17 16:07:09 +0000163\renewcommand{\indexsubitem}{(UDP stream method)}
164
Jack Jansenb721ef11995-03-01 14:54:30 +0000165\begin{funcdesc}{Read}{timeout}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000166Read a datagram, waiting at most \var{timeout} seconds ($-1$ is
Guido van Rossum470be141995-03-17 16:07:09 +0000167infinite). Return the data.
Jack Jansenb721ef11995-03-01 14:54:30 +0000168\end{funcdesc}
169
170\begin{funcdesc}{Write}{host\, port\, buf}
171Send \var{buf} as a datagram to IP-address \var{host}, port
172\var{port}.
173\end{funcdesc}