blob: b5922477bf1e25d225bdd4fbe0a080e682d694c6 [file] [log] [blame]
Fred Drake3a0351c1998-04-04 07:23:21 +00001\section{Built-in Module \module{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
Fred Drake61885921998-04-03 07:16:46 +00006This module provides an interface to the Macintosh TCP/IP driver%
7\index{MacTCP} MacTCP\@. There is an accompanying module,
8\module{macdnr}\refbimodindex{macdnr}, which provides an interface to
9the name-server (allowing you to translate hostnames to IP addresses),
10a module \module{MACTCPconst}\refstmodindex{MACTCPconst} which has
11symbolic names for constants constants used by MacTCP. Since the
12built-in module \module{socket} is also available on the Macintosh it
13is usually easier to use sockets instead of the Macintosh-specific
14MacTCP API.
Jack Jansenb721ef11995-03-01 14:54:30 +000015
16A complete description of the MacTCP interface can be found in the
17Apple MacTCP API documentation.
18
19\begin{funcdesc}{MTU}{}
20Return the Maximum Transmit Unit (the packet size) of the network
Fred Drake61885921998-04-03 07:16:46 +000021interface.\index{Maximum Transmit Unit}
Jack Jansenb721ef11995-03-01 14:54:30 +000022\end{funcdesc}
23
24\begin{funcdesc}{IPAddr}{}
25Return the 32-bit integer IP address of the network interface.
26\end{funcdesc}
27
28\begin{funcdesc}{NetMask}{}
29Return the 32-bit integer network mask of the interface.
30\end{funcdesc}
31
32\begin{funcdesc}{TCPCreate}{size}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000033Create a TCP Stream object. \var{size} is the size of the receive
Jack Jansenb721ef11995-03-01 14:54:30 +000034buffer, \code{4096} is suggested by various sources.
35\end{funcdesc}
36
37\begin{funcdesc}{UDPCreate}{size, port}
Fred Drake61885921998-04-03 07:16:46 +000038Create a UDP Stream object. \var{size} is the size of the receive
Jack Jansenb721ef11995-03-01 14:54:30 +000039buffer (and, hence, the size of the biggest datagram you can receive
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000040on this port). \var{port} is the UDP port number you want to receive
Jack Jansenb721ef11995-03-01 14:54:30 +000041datagrams on, a value of zero will make MacTCP select a free port.
42\end{funcdesc}
43
Fred Drake61885921998-04-03 07:16:46 +000044
Guido van Rossum470be141995-03-17 16:07:09 +000045\subsection{TCP Stream Objects}
46
Fred Drake61885921998-04-03 07:16:46 +000047\begin{memberdesc}[TCP Stream]{asr}
48\index{asynchronous service routine}
49\index{service routine, asynchronous}
50When set to a value different than \code{None} this should refer to a
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000051function with two integer parameters:\ an event code and a detail. This
Jack Jansenb721ef11995-03-01 14:54:30 +000052function will be called upon network-generated events such as urgent
Fred Drake61885921998-04-03 07:16:46 +000053data arrival. Macintosh documentation calls this the
54\dfn{asynchronous service routine}. In addition, it is called with
55eventcode \code{MACTCP.PassiveOpenDone} when a \code{PassiveOpen}
56completes. This is a Python addition to the MacTCP semantics.
57It is safe to do further calls from \var{asr}.
58\end{memberdesc}
Jack Jansenb721ef11995-03-01 14:54:30 +000059
Guido van Rossum470be141995-03-17 16:07:09 +000060
Fred Drake61885921998-04-03 07:16:46 +000061\begin{methoddesc}[TCP Stream]{PassiveOpen}{port}
Jack Jansenb721ef11995-03-01 14:54:30 +000062Wait for an incoming connection on TCP port \var{port} (zero makes the
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000063system pick a free port). The call returns immediately, and you should
Fred Drake61885921998-04-03 07:16:46 +000064use \method{wait()} to wait for completion. You should not issue any method
65calls other than \method{wait()}, \method{isdone()} or
66\method{GetSockName()} before the call completes.
67\end{methoddesc}
Jack Jansenb721ef11995-03-01 14:54:30 +000068
Fred Drake61885921998-04-03 07:16:46 +000069\begin{methoddesc}[TCP Stream]{wait}{}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000070Wait for \code{PassiveOpen} to complete.
Fred Drake61885921998-04-03 07:16:46 +000071\end{methoddesc}
Jack Jansenb721ef11995-03-01 14:54:30 +000072
Fred Drake61885921998-04-03 07:16:46 +000073\begin{methoddesc}[TCP Stream]{isdone}{}
74Return \code{1} if a \code{PassiveOpen} has completed.
75\end{methoddesc}
Jack Jansenb721ef11995-03-01 14:54:30 +000076
Fred Drake61885921998-04-03 07:16:46 +000077\begin{methoddesc}[TCP Stream]{GetSockName}{}
Jack Jansenb721ef11995-03-01 14:54:30 +000078Return the TCP address of this side of a connection as a 2-tuple
Fred Drake61885921998-04-03 07:16:46 +000079\code{(\var{host}, \var{port})}, both integers.
80\end{methoddesc}
Jack Jansenb721ef11995-03-01 14:54:30 +000081
Fred Drake61885921998-04-03 07:16:46 +000082\begin{methoddesc}[TCP Stream]{ActiveOpen}{lport, host, rport}
83Open an outgoing connection to TCP address \code{(\var{host},
84\var{rport})}. Use
Jack Jansenb721ef11995-03-01 14:54:30 +000085local port \var{lport} (zero makes the system pick a free port). This
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000086call blocks until the connection has been established.
Fred Drake61885921998-04-03 07:16:46 +000087\end{methoddesc}
Jack Jansenb721ef11995-03-01 14:54:30 +000088
Fred Drake61885921998-04-03 07:16:46 +000089\begin{methoddesc}[TCP Stream]{Send}{buf, push, urgent}
90Send data \var{buf} over the connection. \var{push} and \var{urgent}
Jack Jansenb721ef11995-03-01 14:54:30 +000091are flags as specified by the TCP standard.
Fred Drake61885921998-04-03 07:16:46 +000092\end{methoddesc}
Jack Jansenb721ef11995-03-01 14:54:30 +000093
Fred Drake61885921998-04-03 07:16:46 +000094\begin{methoddesc}[TCP Stream]{Rcv}{timeout}
Jack Jansenb721ef11995-03-01 14:54:30 +000095Receive data. The call returns when \var{timeout} seconds have passed
96or when (according to the MacTCP documentation) ``a reasonable amount
97of data has been received''. The return value is a 3-tuple
Fred Drake61885921998-04-03 07:16:46 +000098\code{(\var{data}, \var{urgent}, \var{mark})}. If urgent data is
99outstanding \code{Rcv} will always return that before looking at any
100normal data. The first call returning urgent data will have the
101\var{urgent} flag set, the last will have the \var{mark} flag set.
102\end{methoddesc}
Jack Jansenb721ef11995-03-01 14:54:30 +0000103
Fred Drake61885921998-04-03 07:16:46 +0000104\begin{methoddesc}[TCP Stream]{Close}{}
Jack Jansenb721ef11995-03-01 14:54:30 +0000105Tell MacTCP that no more data will be transmitted on this
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000106connection. The call returns when all data has been acknowledged by
Jack Jansenb721ef11995-03-01 14:54:30 +0000107the receiving side.
Fred Drake61885921998-04-03 07:16:46 +0000108\end{methoddesc}
Jack Jansenb721ef11995-03-01 14:54:30 +0000109
Fred Drake61885921998-04-03 07:16:46 +0000110\begin{methoddesc}[TCP Stream]{Abort}{}
Jack Jansenb721ef11995-03-01 14:54:30 +0000111Forcibly close both sides of a connection, ignoring outstanding data.
Fred Drake61885921998-04-03 07:16:46 +0000112\end{methoddesc}
Jack Jansenb721ef11995-03-01 14:54:30 +0000113
Fred Drake61885921998-04-03 07:16:46 +0000114\begin{methoddesc}[TCP Stream]{Status}{}
Guido van Rossum470be141995-03-17 16:07:09 +0000115Return a TCP status object for this stream giving the current status
116(see below).
Fred Drake61885921998-04-03 07:16:46 +0000117\end{methoddesc}
118
Jack Jansenb721ef11995-03-01 14:54:30 +0000119
Guido van Rossum470be141995-03-17 16:07:09 +0000120\subsection{TCP Status Objects}
Fred Drake61885921998-04-03 07:16:46 +0000121
Jack Jansenb721ef11995-03-01 14:54:30 +0000122This object has no methods, only some members holding information on
123the connection. A complete description of all fields in this objects
124can be found in the Apple documentation. The most interesting ones are:
125
Fred Drake61885921998-04-03 07:16:46 +0000126\begin{memberdesc}[TCP Status]{localHost}
127\memberline{localPort}
128\memberline{remoteHost}
129\memberline{remotePort}
Jack Jansenb721ef11995-03-01 14:54:30 +0000130The integer IP-addresses and port numbers of both endpoints of the
131connection.
Fred Drake61885921998-04-03 07:16:46 +0000132\end{memberdesc}
Jack Jansenb721ef11995-03-01 14:54:30 +0000133
Fred Drake61885921998-04-03 07:16:46 +0000134\begin{memberdesc}[TCP Status]{sendWindow}
Jack Jansenb721ef11995-03-01 14:54:30 +0000135The current window size.
Fred Drake61885921998-04-03 07:16:46 +0000136\end{memberdesc}
Jack Jansenb721ef11995-03-01 14:54:30 +0000137
Fred Drake61885921998-04-03 07:16:46 +0000138\begin{memberdesc}[TCP Status]{amtUnackedData}
Jack Jansenb721ef11995-03-01 14:54:30 +0000139The number of bytes sent but not yet acknowledged. \code{sendWindow -
Fred Drake61885921998-04-03 07:16:46 +0000140amtUnackedData} is what you can pass to \method{Send()} without
141blocking.
142\end{memberdesc}
Jack Jansenb721ef11995-03-01 14:54:30 +0000143
Fred Drake61885921998-04-03 07:16:46 +0000144\begin{memberdesc}[TCP Status]{amtUnreadData}
145The number of bytes received but not yet read (what you can
146\method{Recv()} without blocking).
147\end{memberdesc}
Jack Jansenb721ef11995-03-01 14:54:30 +0000148
149
150
Guido van Rossum470be141995-03-17 16:07:09 +0000151\subsection{UDP Stream Objects}
Fred Drake61885921998-04-03 07:16:46 +0000152
Jack Jansenb721ef11995-03-01 14:54:30 +0000153Note that, unlike the name suggests, there is nothing stream-like
154about UDP.
155
Jack Jansenb721ef11995-03-01 14:54:30 +0000156
Fred Drake61885921998-04-03 07:16:46 +0000157\begin{memberdesc}[UDP Stream]{asr}
158\index{asynchronous service routine}
159\index{service routine, asynchronous}
Jack Jansenb721ef11995-03-01 14:54:30 +0000160The asynchronous service routine to be called on events such as
Fred Drake61885921998-04-03 07:16:46 +0000161datagram arrival without outstanding \code{Read} call. The \var{asr}
162has a single argument, the event code.
163\end{memberdesc}
Jack Jansenb721ef11995-03-01 14:54:30 +0000164
Fred Drake61885921998-04-03 07:16:46 +0000165\begin{memberdesc}[UDP Stream]{port}
166A read-only member giving the port number of this UDP Stream.
167\end{memberdesc}
Jack Jansenb721ef11995-03-01 14:54:30 +0000168
Guido van Rossum470be141995-03-17 16:07:09 +0000169
Fred Drake61885921998-04-03 07:16:46 +0000170\begin{methoddesc}[UDP Stream]{Read}{timeout}
Guido van Rossumf259efe1997-11-25 01:00:40 +0000171Read a datagram, waiting at most \var{timeout} seconds (-1 is
Guido van Rossum470be141995-03-17 16:07:09 +0000172infinite). Return the data.
Fred Drake61885921998-04-03 07:16:46 +0000173\end{methoddesc}
Jack Jansenb721ef11995-03-01 14:54:30 +0000174
Fred Drake61885921998-04-03 07:16:46 +0000175\begin{methoddesc}[UDP Stream]{Write}{host, port, buf}
Jack Jansenb721ef11995-03-01 14:54:30 +0000176Send \var{buf} as a datagram to IP-address \var{host}, port
177\var{port}.
Fred Drake61885921998-04-03 07:16:46 +0000178\end{methoddesc}