blob: f5590c5a103d65cc4190397b6982d3f2a4f378f6 [file] [log] [blame]
Fred Drake3a0351c1998-04-04 07:23:21 +00001\section{Built-in Module \module{mactcp}}
Fred Drakefe7f3bc1998-07-23 17:55:31 +00002\declaremodule{builtin}{mactcp}
3
4\modulesynopsis{The MacTCP interfaces.}
5
Guido van Rossum470be141995-03-17 16:07:09 +00006
Jack Jansenb721ef11995-03-01 14:54:30 +00007
Fred Drake61885921998-04-03 07:16:46 +00008This module provides an interface to the Macintosh TCP/IP driver%
9\index{MacTCP} MacTCP\@. There is an accompanying module,
10\module{macdnr}\refbimodindex{macdnr}, which provides an interface to
11the name-server (allowing you to translate hostnames to IP addresses),
12a module \module{MACTCPconst}\refstmodindex{MACTCPconst} which has
13symbolic names for constants constants used by MacTCP. Since the
14built-in module \module{socket} is also available on the Macintosh it
15is usually easier to use sockets instead of the Macintosh-specific
16MacTCP API.
Jack Jansenb721ef11995-03-01 14:54:30 +000017
18A complete description of the MacTCP interface can be found in the
19Apple MacTCP API documentation.
20
21\begin{funcdesc}{MTU}{}
22Return the Maximum Transmit Unit (the packet size) of the network
Fred Drake61885921998-04-03 07:16:46 +000023interface.\index{Maximum Transmit Unit}
Jack Jansenb721ef11995-03-01 14:54:30 +000024\end{funcdesc}
25
26\begin{funcdesc}{IPAddr}{}
27Return the 32-bit integer IP address of the network interface.
28\end{funcdesc}
29
30\begin{funcdesc}{NetMask}{}
31Return the 32-bit integer network mask of the interface.
32\end{funcdesc}
33
34\begin{funcdesc}{TCPCreate}{size}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000035Create a TCP Stream object. \var{size} is the size of the receive
Jack Jansenb721ef11995-03-01 14:54:30 +000036buffer, \code{4096} is suggested by various sources.
37\end{funcdesc}
38
39\begin{funcdesc}{UDPCreate}{size, port}
Fred Drake61885921998-04-03 07:16:46 +000040Create a UDP Stream object. \var{size} is the size of the receive
Jack Jansenb721ef11995-03-01 14:54:30 +000041buffer (and, hence, the size of the biggest datagram you can receive
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000042on this port). \var{port} is the UDP port number you want to receive
Jack Jansenb721ef11995-03-01 14:54:30 +000043datagrams on, a value of zero will make MacTCP select a free port.
44\end{funcdesc}
45
Fred Drake61885921998-04-03 07:16:46 +000046
Guido van Rossum470be141995-03-17 16:07:09 +000047\subsection{TCP Stream Objects}
48
Fred Drake61885921998-04-03 07:16:46 +000049\begin{memberdesc}[TCP Stream]{asr}
50\index{asynchronous service routine}
51\index{service routine, asynchronous}
52When set to a value different than \code{None} this should refer to a
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000053function with two integer parameters:\ an event code and a detail. This
Jack Jansenb721ef11995-03-01 14:54:30 +000054function will be called upon network-generated events such as urgent
Fred Drake61885921998-04-03 07:16:46 +000055data arrival. Macintosh documentation calls this the
56\dfn{asynchronous service routine}. In addition, it is called with
57eventcode \code{MACTCP.PassiveOpenDone} when a \code{PassiveOpen}
58completes. This is a Python addition to the MacTCP semantics.
59It is safe to do further calls from \var{asr}.
60\end{memberdesc}
Jack Jansenb721ef11995-03-01 14:54:30 +000061
Guido van Rossum470be141995-03-17 16:07:09 +000062
Fred Drake61885921998-04-03 07:16:46 +000063\begin{methoddesc}[TCP Stream]{PassiveOpen}{port}
Jack Jansenb721ef11995-03-01 14:54:30 +000064Wait for an incoming connection on TCP port \var{port} (zero makes the
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000065system pick a free port). The call returns immediately, and you should
Fred Drake61885921998-04-03 07:16:46 +000066use \method{wait()} to wait for completion. You should not issue any method
67calls other than \method{wait()}, \method{isdone()} or
68\method{GetSockName()} before the call completes.
69\end{methoddesc}
Jack Jansenb721ef11995-03-01 14:54:30 +000070
Fred Drake61885921998-04-03 07:16:46 +000071\begin{methoddesc}[TCP Stream]{wait}{}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000072Wait for \code{PassiveOpen} to complete.
Fred Drake61885921998-04-03 07:16:46 +000073\end{methoddesc}
Jack Jansenb721ef11995-03-01 14:54:30 +000074
Fred Drake61885921998-04-03 07:16:46 +000075\begin{methoddesc}[TCP Stream]{isdone}{}
76Return \code{1} if a \code{PassiveOpen} has completed.
77\end{methoddesc}
Jack Jansenb721ef11995-03-01 14:54:30 +000078
Fred Drake61885921998-04-03 07:16:46 +000079\begin{methoddesc}[TCP Stream]{GetSockName}{}
Jack Jansenb721ef11995-03-01 14:54:30 +000080Return the TCP address of this side of a connection as a 2-tuple
Fred Drake61885921998-04-03 07:16:46 +000081\code{(\var{host}, \var{port})}, both integers.
82\end{methoddesc}
Jack Jansenb721ef11995-03-01 14:54:30 +000083
Fred Drake61885921998-04-03 07:16:46 +000084\begin{methoddesc}[TCP Stream]{ActiveOpen}{lport, host, rport}
85Open an outgoing connection to TCP address \code{(\var{host},
86\var{rport})}. Use
Jack Jansenb721ef11995-03-01 14:54:30 +000087local port \var{lport} (zero makes the system pick a free port). This
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000088call blocks until the connection has been established.
Fred Drake61885921998-04-03 07:16:46 +000089\end{methoddesc}
Jack Jansenb721ef11995-03-01 14:54:30 +000090
Fred Drake61885921998-04-03 07:16:46 +000091\begin{methoddesc}[TCP Stream]{Send}{buf, push, urgent}
92Send data \var{buf} over the connection. \var{push} and \var{urgent}
Jack Jansenb721ef11995-03-01 14:54:30 +000093are flags as specified by the TCP standard.
Fred Drake61885921998-04-03 07:16:46 +000094\end{methoddesc}
Jack Jansenb721ef11995-03-01 14:54:30 +000095
Fred Drake61885921998-04-03 07:16:46 +000096\begin{methoddesc}[TCP Stream]{Rcv}{timeout}
Jack Jansenb721ef11995-03-01 14:54:30 +000097Receive data. The call returns when \var{timeout} seconds have passed
98or when (according to the MacTCP documentation) ``a reasonable amount
99of data has been received''. The return value is a 3-tuple
Fred Drake61885921998-04-03 07:16:46 +0000100\code{(\var{data}, \var{urgent}, \var{mark})}. If urgent data is
101outstanding \code{Rcv} will always return that before looking at any
102normal data. The first call returning urgent data will have the
103\var{urgent} flag set, the last will have the \var{mark} flag set.
104\end{methoddesc}
Jack Jansenb721ef11995-03-01 14:54:30 +0000105
Fred Drake61885921998-04-03 07:16:46 +0000106\begin{methoddesc}[TCP Stream]{Close}{}
Jack Jansenb721ef11995-03-01 14:54:30 +0000107Tell MacTCP that no more data will be transmitted on this
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000108connection. The call returns when all data has been acknowledged by
Jack Jansenb721ef11995-03-01 14:54:30 +0000109the receiving side.
Fred Drake61885921998-04-03 07:16:46 +0000110\end{methoddesc}
Jack Jansenb721ef11995-03-01 14:54:30 +0000111
Fred Drake61885921998-04-03 07:16:46 +0000112\begin{methoddesc}[TCP Stream]{Abort}{}
Jack Jansenb721ef11995-03-01 14:54:30 +0000113Forcibly close both sides of a connection, ignoring outstanding data.
Fred Drake61885921998-04-03 07:16:46 +0000114\end{methoddesc}
Jack Jansenb721ef11995-03-01 14:54:30 +0000115
Fred Drake61885921998-04-03 07:16:46 +0000116\begin{methoddesc}[TCP Stream]{Status}{}
Guido van Rossum470be141995-03-17 16:07:09 +0000117Return a TCP status object for this stream giving the current status
118(see below).
Fred Drake61885921998-04-03 07:16:46 +0000119\end{methoddesc}
120
Jack Jansenb721ef11995-03-01 14:54:30 +0000121
Guido van Rossum470be141995-03-17 16:07:09 +0000122\subsection{TCP Status Objects}
Fred Drake61885921998-04-03 07:16:46 +0000123
Jack Jansenb721ef11995-03-01 14:54:30 +0000124This object has no methods, only some members holding information on
125the connection. A complete description of all fields in this objects
126can be found in the Apple documentation. The most interesting ones are:
127
Fred Drake61885921998-04-03 07:16:46 +0000128\begin{memberdesc}[TCP Status]{localHost}
129\memberline{localPort}
130\memberline{remoteHost}
131\memberline{remotePort}
Jack Jansenb721ef11995-03-01 14:54:30 +0000132The integer IP-addresses and port numbers of both endpoints of the
133connection.
Fred Drake61885921998-04-03 07:16:46 +0000134\end{memberdesc}
Jack Jansenb721ef11995-03-01 14:54:30 +0000135
Fred Drake61885921998-04-03 07:16:46 +0000136\begin{memberdesc}[TCP Status]{sendWindow}
Jack Jansenb721ef11995-03-01 14:54:30 +0000137The current window size.
Fred Drake61885921998-04-03 07:16:46 +0000138\end{memberdesc}
Jack Jansenb721ef11995-03-01 14:54:30 +0000139
Fred Drake61885921998-04-03 07:16:46 +0000140\begin{memberdesc}[TCP Status]{amtUnackedData}
Jack Jansenb721ef11995-03-01 14:54:30 +0000141The number of bytes sent but not yet acknowledged. \code{sendWindow -
Fred Drake61885921998-04-03 07:16:46 +0000142amtUnackedData} is what you can pass to \method{Send()} without
143blocking.
144\end{memberdesc}
Jack Jansenb721ef11995-03-01 14:54:30 +0000145
Fred Drake61885921998-04-03 07:16:46 +0000146\begin{memberdesc}[TCP Status]{amtUnreadData}
147The number of bytes received but not yet read (what you can
148\method{Recv()} without blocking).
149\end{memberdesc}
Jack Jansenb721ef11995-03-01 14:54:30 +0000150
151
152
Guido van Rossum470be141995-03-17 16:07:09 +0000153\subsection{UDP Stream Objects}
Fred Drake61885921998-04-03 07:16:46 +0000154
Jack Jansenb721ef11995-03-01 14:54:30 +0000155Note that, unlike the name suggests, there is nothing stream-like
156about UDP.
157
Jack Jansenb721ef11995-03-01 14:54:30 +0000158
Fred Drake61885921998-04-03 07:16:46 +0000159\begin{memberdesc}[UDP Stream]{asr}
160\index{asynchronous service routine}
161\index{service routine, asynchronous}
Jack Jansenb721ef11995-03-01 14:54:30 +0000162The asynchronous service routine to be called on events such as
Fred Drake61885921998-04-03 07:16:46 +0000163datagram arrival without outstanding \code{Read} call. The \var{asr}
164has a single argument, the event code.
165\end{memberdesc}
Jack Jansenb721ef11995-03-01 14:54:30 +0000166
Fred Drake61885921998-04-03 07:16:46 +0000167\begin{memberdesc}[UDP Stream]{port}
168A read-only member giving the port number of this UDP Stream.
169\end{memberdesc}
Jack Jansenb721ef11995-03-01 14:54:30 +0000170
Guido van Rossum470be141995-03-17 16:07:09 +0000171
Fred Drake61885921998-04-03 07:16:46 +0000172\begin{methoddesc}[UDP Stream]{Read}{timeout}
Guido van Rossumf259efe1997-11-25 01:00:40 +0000173Read a datagram, waiting at most \var{timeout} seconds (-1 is
Guido van Rossum470be141995-03-17 16:07:09 +0000174infinite). Return the data.
Fred Drake61885921998-04-03 07:16:46 +0000175\end{methoddesc}
Jack Jansenb721ef11995-03-01 14:54:30 +0000176
Fred Drake61885921998-04-03 07:16:46 +0000177\begin{methoddesc}[UDP Stream]{Write}{host, port, buf}
Jack Jansenb721ef11995-03-01 14:54:30 +0000178Send \var{buf} as a datagram to IP-address \var{host}, port
179\var{port}.
Fred Drake61885921998-04-03 07:16:46 +0000180\end{methoddesc}