blob: 4d6d5ba85539673e8ba08f23bdddcbb3361f3c04 [file] [log] [blame]
Guido van Rossum470be141995-03-17 16:07:09 +00001\section{Built-in Module \sectcode{mactcp}}
Guido van Rossume47da0a1997-07-17 16:34:52 +00002\label{module-mactcp}
Jack Jansenb721ef11995-03-01 14:54:30 +00003\bimodindex{mactcp}
Guido van Rossum470be141995-03-17 16:07:09 +00004
Jack Jansenb721ef11995-03-01 14:54:30 +00005\renewcommand{\indexsubitem}{(in module mactcp)}
6
7This module provides an interface to the Macintosh TCP/IP driver
Guido van Rossum6bb1adc1995-03-13 10:03:32 +00008MacTCP\@. There is an accompanying module \code{macdnr} which provides an
Jack Jansenb721ef11995-03-01 14:54:30 +00009interface to the name-server (allowing you to translate hostnames to
Guido van Rossum66774a91996-07-21 02:20:58 +000010ip-addresses), a module \code{MACTCPconst} which has symbolic names for
11constants constants used by MacTCP. Since the builtin module
12\code{socket} is also available on the mac it is usually easier to use
13sockets in stead of the mac-specific MacTCP API.
Jack Jansenb721ef11995-03-01 14:54:30 +000014
15A complete description of the MacTCP interface can be found in the
16Apple MacTCP API documentation.
17
18\begin{funcdesc}{MTU}{}
19Return the Maximum Transmit Unit (the packet size) of the network
20interface.
21\end{funcdesc}
22
23\begin{funcdesc}{IPAddr}{}
24Return the 32-bit integer IP address of the network interface.
25\end{funcdesc}
26
27\begin{funcdesc}{NetMask}{}
28Return the 32-bit integer network mask of the interface.
29\end{funcdesc}
30
31\begin{funcdesc}{TCPCreate}{size}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000032Create a TCP Stream object. \var{size} is the size of the receive
Jack Jansenb721ef11995-03-01 14:54:30 +000033buffer, \code{4096} is suggested by various sources.
34\end{funcdesc}
35
36\begin{funcdesc}{UDPCreate}{size, port}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000037Create a UDP stream object. \var{size} is the size of the receive
Jack Jansenb721ef11995-03-01 14:54:30 +000038buffer (and, hence, the size of the biggest datagram you can receive
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000039on this port). \var{port} is the UDP port number you want to receive
Jack Jansenb721ef11995-03-01 14:54:30 +000040datagrams on, a value of zero will make MacTCP select a free port.
41\end{funcdesc}
42
Guido van Rossum470be141995-03-17 16:07:09 +000043\subsection{TCP Stream Objects}
44
45\renewcommand{\indexsubitem}{(TCP stream attribute)}
Jack Jansenb721ef11995-03-01 14:54:30 +000046
47\begin{datadesc}{asr}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000048When set to a value different than \code{None} this should point to a
49function with two integer parameters:\ an event code and a detail. This
Jack Jansenb721ef11995-03-01 14:54:30 +000050function will be called upon network-generated events such as urgent
51data arrival. In addition, it is called with eventcode
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000052\code{MACTCP.PassiveOpenDone} when a \code{PassiveOpen} completes. This
53is a Python addition to the MacTCP semantics.
54It is safe to do further calls from the \code{asr}.
Jack Jansenb721ef11995-03-01 14:54:30 +000055\end{datadesc}
56
Guido van Rossum470be141995-03-17 16:07:09 +000057\renewcommand{\indexsubitem}{(TCP stream method)}
58
Jack Jansenb721ef11995-03-01 14:54:30 +000059\begin{funcdesc}{PassiveOpen}{port}
60Wait for an incoming connection on TCP port \var{port} (zero makes the
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000061system pick a free port). The call returns immediately, and you should
Jack Jansenb721ef11995-03-01 14:54:30 +000062use \var{wait} to wait for completion. You should not issue any method
63calls other than
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000064\code{wait}, \code{isdone} or \code{GetSockName} before the call
Jack Jansenb721ef11995-03-01 14:54:30 +000065completes.
66\end{funcdesc}
67
68\begin{funcdesc}{wait}{}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000069Wait for \code{PassiveOpen} to complete.
Jack Jansenb721ef11995-03-01 14:54:30 +000070\end{funcdesc}
71
72\begin{funcdesc}{isdone}{}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000073Return 1 if a \code{PassiveOpen} has completed.
Jack Jansenb721ef11995-03-01 14:54:30 +000074\end{funcdesc}
75
76\begin{funcdesc}{GetSockName}{}
77Return the TCP address of this side of a connection as a 2-tuple
78\code{(host, port)}, both integers.
79\end{funcdesc}
80
81\begin{funcdesc}{ActiveOpen}{lport\, host\, rport}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000082Open an outgoing connection to TCP address \code{(\var{host}, \var{rport})}. Use
Jack Jansenb721ef11995-03-01 14:54:30 +000083local port \var{lport} (zero makes the system pick a free port). This
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000084call blocks until the connection has been established.
Jack Jansenb721ef11995-03-01 14:54:30 +000085\end{funcdesc}
86
87\begin{funcdesc}{Send}{buf\, push\, urgent}
88Send data \var{buf} over the connection. \var{Push} and \var{urgent}
89are flags as specified by the TCP standard.
90\end{funcdesc}
91
92\begin{funcdesc}{Rcv}{timeout}
93Receive data. The call returns when \var{timeout} seconds have passed
94or when (according to the MacTCP documentation) ``a reasonable amount
95of data has been received''. The return value is a 3-tuple
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000096\code{(\var{data}, \var{urgent}, \var{mark})}. If urgent data is outstanding \code{Rcv}
Jack Jansenb721ef11995-03-01 14:54:30 +000097will always return that before looking at any normal data. The first
98call returning urgent data will have the \var{urgent} flag set, the
99last will have the \var{mark} flag set.
100\end{funcdesc}
101
102\begin{funcdesc}{Close}{}
103Tell MacTCP that no more data will be transmitted on this
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000104connection. The call returns when all data has been acknowledged by
Jack Jansenb721ef11995-03-01 14:54:30 +0000105the receiving side.
106\end{funcdesc}
107
108\begin{funcdesc}{Abort}{}
109Forcibly close both sides of a connection, ignoring outstanding data.
110\end{funcdesc}
111
112\begin{funcdesc}{Status}{}
Guido van Rossum470be141995-03-17 16:07:09 +0000113Return a TCP status object for this stream giving the current status
114(see below).
Jack Jansenb721ef11995-03-01 14:54:30 +0000115\end{funcdesc}
116
Guido van Rossum470be141995-03-17 16:07:09 +0000117\subsection{TCP Status Objects}
Jack Jansenb721ef11995-03-01 14:54:30 +0000118This object has no methods, only some members holding information on
119the connection. A complete description of all fields in this objects
120can be found in the Apple documentation. The most interesting ones are:
121
Guido van Rossum470be141995-03-17 16:07:09 +0000122\renewcommand{\indexsubitem}{(TCP status attribute)}
123
Jack Jansenb721ef11995-03-01 14:54:30 +0000124\begin{datadesc}{localHost}
125\dataline{localPort}
126\dataline{remoteHost}
127\dataline{remotePort}
128The integer IP-addresses and port numbers of both endpoints of the
129connection.
130\end{datadesc}
131
132\begin{datadesc}{sendWindow}
133The current window size.
134\end{datadesc}
135
136\begin{datadesc}{amtUnackedData}
137The number of bytes sent but not yet acknowledged. \code{sendWindow -
138amtUnackedData} is what you can pass to \code{Send} without blocking.
139\end{datadesc}
140
141\begin{datadesc}{amtUnreadData}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000142The number of bytes received but not yet read (what you can \code{Recv}
Jack Jansenb721ef11995-03-01 14:54:30 +0000143without blocking).
144\end{datadesc}
145
146
147
Guido van Rossum470be141995-03-17 16:07:09 +0000148\subsection{UDP Stream Objects}
Jack Jansenb721ef11995-03-01 14:54:30 +0000149Note that, unlike the name suggests, there is nothing stream-like
150about UDP.
151
Guido van Rossum470be141995-03-17 16:07:09 +0000152\renewcommand{\indexsubitem}{(UDP stream attribute)}
Jack Jansenb721ef11995-03-01 14:54:30 +0000153
154\begin{datadesc}{asr}
155The asynchronous service routine to be called on events such as
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000156datagram arrival without outstanding \code{Read} call. The \code{asr} has a
Jack Jansenb721ef11995-03-01 14:54:30 +0000157single argument, the event code.
158\end{datadesc}
159
160\begin{datadesc}{port}
161A read-only member giving the port number of this UDP stream.
162\end{datadesc}
163
Guido van Rossum470be141995-03-17 16:07:09 +0000164\renewcommand{\indexsubitem}{(UDP stream method)}
165
Jack Jansenb721ef11995-03-01 14:54:30 +0000166\begin{funcdesc}{Read}{timeout}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000167Read a datagram, waiting at most \var{timeout} seconds ($-1$ is
Guido van Rossum470be141995-03-17 16:07:09 +0000168infinite). Return the data.
Jack Jansenb721ef11995-03-01 14:54:30 +0000169\end{funcdesc}
170
171\begin{funcdesc}{Write}{host\, port\, buf}
172Send \var{buf} as a datagram to IP-address \var{host}, port
173\var{port}.
174\end{funcdesc}