blob: 11c011420563df205295a74ac4794a8a27924ac1 [file] [log] [blame]
Jack Jansenb721ef11995-03-01 14:54:30 +00001\section{Built-in module \sectcode{mactcp}}
2\bimodindex{mactcp}
3\renewcommand{\indexsubitem}{(in module mactcp)}
4
5This module provides an interface to the Macintosh TCP/IP driver
Guido van Rossum6bb1adc1995-03-13 10:03:32 +00006MacTCP\@. There is an accompanying module \code{macdnr} which provides an
Jack Jansenb721ef11995-03-01 14:54:30 +00007interface to the name-server (allowing you to translate hostnames to
Guido van Rossum6bb1adc1995-03-13 10:03:32 +00008ip-addresses), a module \code{MACTCP} which has symbolic names for
9constants constants used by MacTCP and a wrapper module \code{socket}
10which mimics the \UNIX{} socket interface (as far as possible).
Jack Jansenb721ef11995-03-01 14:54:30 +000011
12A complete description of the MacTCP interface can be found in the
13Apple MacTCP API documentation.
14
15\begin{funcdesc}{MTU}{}
16Return the Maximum Transmit Unit (the packet size) of the network
17interface.
18\end{funcdesc}
19
20\begin{funcdesc}{IPAddr}{}
21Return the 32-bit integer IP address of the network interface.
22\end{funcdesc}
23
24\begin{funcdesc}{NetMask}{}
25Return the 32-bit integer network mask of the interface.
26\end{funcdesc}
27
28\begin{funcdesc}{TCPCreate}{size}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000029Create a TCP Stream object. \var{size} is the size of the receive
Jack Jansenb721ef11995-03-01 14:54:30 +000030buffer, \code{4096} is suggested by various sources.
31\end{funcdesc}
32
33\begin{funcdesc}{UDPCreate}{size, port}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000034Create a UDP stream object. \var{size} is the size of the receive
Jack Jansenb721ef11995-03-01 14:54:30 +000035buffer (and, hence, the size of the biggest datagram you can receive
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000036on this port). \var{port} is the UDP port number you want to receive
Jack Jansenb721ef11995-03-01 14:54:30 +000037datagrams on, a value of zero will make MacTCP select a free port.
38\end{funcdesc}
39
40\subsection{TCP stream objects}
41\renewcommand{\indexsubitem}{(TCP stream method)}
42
43\begin{datadesc}{asr}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000044When set to a value different than \code{None} this should point to a
45function with two integer parameters:\ an event code and a detail. This
Jack Jansenb721ef11995-03-01 14:54:30 +000046function will be called upon network-generated events such as urgent
47data arrival. In addition, it is called with eventcode
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000048\code{MACTCP.PassiveOpenDone} when a \code{PassiveOpen} completes. This
49is a Python addition to the MacTCP semantics.
50It is safe to do further calls from the \code{asr}.
Jack Jansenb721ef11995-03-01 14:54:30 +000051\end{datadesc}
52
53\begin{funcdesc}{PassiveOpen}{port}
54Wait for an incoming connection on TCP port \var{port} (zero makes the
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000055system pick a free port). The call returns immediately, and you should
Jack Jansenb721ef11995-03-01 14:54:30 +000056use \var{wait} to wait for completion. You should not issue any method
57calls other than
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000058\code{wait}, \code{isdone} or \code{GetSockName} before the call
Jack Jansenb721ef11995-03-01 14:54:30 +000059completes.
60\end{funcdesc}
61
62\begin{funcdesc}{wait}{}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000063Wait for \code{PassiveOpen} to complete.
Jack Jansenb721ef11995-03-01 14:54:30 +000064\end{funcdesc}
65
66\begin{funcdesc}{isdone}{}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000067Return 1 if a \code{PassiveOpen} has completed.
Jack Jansenb721ef11995-03-01 14:54:30 +000068\end{funcdesc}
69
70\begin{funcdesc}{GetSockName}{}
71Return the TCP address of this side of a connection as a 2-tuple
72\code{(host, port)}, both integers.
73\end{funcdesc}
74
75\begin{funcdesc}{ActiveOpen}{lport\, host\, rport}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000076Open an outgoing connection to TCP address \code{(\var{host}, \var{rport})}. Use
Jack Jansenb721ef11995-03-01 14:54:30 +000077local port \var{lport} (zero makes the system pick a free port). This
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000078call blocks until the connection has been established.
Jack Jansenb721ef11995-03-01 14:54:30 +000079\end{funcdesc}
80
81\begin{funcdesc}{Send}{buf\, push\, urgent}
82Send data \var{buf} over the connection. \var{Push} and \var{urgent}
83are flags as specified by the TCP standard.
84\end{funcdesc}
85
86\begin{funcdesc}{Rcv}{timeout}
87Receive data. The call returns when \var{timeout} seconds have passed
88or when (according to the MacTCP documentation) ``a reasonable amount
89of data has been received''. The return value is a 3-tuple
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000090\code{(\var{data}, \var{urgent}, \var{mark})}. If urgent data is outstanding \code{Rcv}
Jack Jansenb721ef11995-03-01 14:54:30 +000091will always return that before looking at any normal data. The first
92call returning urgent data will have the \var{urgent} flag set, the
93last will have the \var{mark} flag set.
94\end{funcdesc}
95
96\begin{funcdesc}{Close}{}
97Tell MacTCP that no more data will be transmitted on this
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000098connection. The call returns when all data has been acknowledged by
Jack Jansenb721ef11995-03-01 14:54:30 +000099the receiving side.
100\end{funcdesc}
101
102\begin{funcdesc}{Abort}{}
103Forcibly close both sides of a connection, ignoring outstanding data.
104\end{funcdesc}
105
106\begin{funcdesc}{Status}{}
107Return a TCP status object for this stream.
108\end{funcdesc}
109
110\subsection{TCP status objects}
111This object has no methods, only some members holding information on
112the connection. A complete description of all fields in this objects
113can be found in the Apple documentation. The most interesting ones are:
114
115\renewcommand{\indexsubitem}{(TCP status method)}
116\begin{datadesc}{localHost}
117\dataline{localPort}
118\dataline{remoteHost}
119\dataline{remotePort}
120The integer IP-addresses and port numbers of both endpoints of the
121connection.
122\end{datadesc}
123
124\begin{datadesc}{sendWindow}
125The current window size.
126\end{datadesc}
127
128\begin{datadesc}{amtUnackedData}
129The number of bytes sent but not yet acknowledged. \code{sendWindow -
130amtUnackedData} is what you can pass to \code{Send} without blocking.
131\end{datadesc}
132
133\begin{datadesc}{amtUnreadData}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000134The number of bytes received but not yet read (what you can \code{Recv}
Jack Jansenb721ef11995-03-01 14:54:30 +0000135without blocking).
136\end{datadesc}
137
138
139
140\subsection{UDP stream objects}
141Note that, unlike the name suggests, there is nothing stream-like
142about UDP.
143
144\renewcommand{\indexsubitem}{(UDP stream method)}
145
146\begin{datadesc}{asr}
147The asynchronous service routine to be called on events such as
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000148datagram arrival without outstanding \code{Read} call. The \code{asr} has a
Jack Jansenb721ef11995-03-01 14:54:30 +0000149single argument, the event code.
150\end{datadesc}
151
152\begin{datadesc}{port}
153A read-only member giving the port number of this UDP stream.
154\end{datadesc}
155
156\begin{funcdesc}{Read}{timeout}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000157Read a datagram, waiting at most \var{timeout} seconds ($-1$ is
158indefinite). Return the data.
Jack Jansenb721ef11995-03-01 14:54:30 +0000159\end{funcdesc}
160
161\begin{funcdesc}{Write}{host\, port\, buf}
162Send \var{buf} as a datagram to IP-address \var{host}, port
163\var{port}.
164\end{funcdesc}