blob: 6f8719ece47e915c4da245382b2c0b8899f6198a [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
6MacTCP. There is an accompanying module \var{macdnr} which provides an
7interface to the name-server (allowing you to translate hostnames to
8ip-addresses), a module \var{MACTCP} which has symbolic names for
9constants constants used by MacTCP and a wrapper module \var{socket}
10which mimics the unix socket interface (as far as possible).
11
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}
29Create a TCP Stream object. \var{Size} is the size of the receive
30buffer, \code{4096} is suggested by various sources.
31\end{funcdesc}
32
33\begin{funcdesc}{UDPCreate}{size, port}
34Create a UDP stream object. \var{Size} is the size of the receive
35buffer (and, hence, the size of the biggest datagram you can receive
36on this port). \var{Port} is the UDP port number you want to receive
37datagrams 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}
44When set to a value different than \var{None} this should point to a
45function with two integer parameters: an event code and a detail. This
46function will be called upon network-generated events such as urgent
47data arrival. In addition, it is called with eventcode
48\var{MACTCP.PassiveOpenDone} when a \var{PassiveOpen} completes. This
49is a python addition to the MacTCP semantics.
50It is safe to do further calls from the asr.
51\end{datadesc}
52
53\begin{funcdesc}{PassiveOpen}{port}
54Wait for an incoming connection on TCP port \var{port} (zero makes the
55system pick a free port). The call returns immedeately, and you should
56use \var{wait} to wait for completion. You should not issue any method
57calls other than
58\var{wait}, \var{isdone} or \var{GetSockName} before the call
59completes.
60\end{funcdesc}
61
62\begin{funcdesc}{wait}{}
63Wait for \var{PassiveOpen} to complete.
64\end{funcdesc}
65
66\begin{funcdesc}{isdone}{}
67Return 1 if a \var{PassiveOpen} is completed.
68\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}
76Open an outgoing connection to TCP address \code{(host, rport)}. Use
77local port \var{lport} (zero makes the system pick a free port). This
78call blocks until the connection is established.
79\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
90\code{(data, urgent, mark)}. If urgent data is outstanding \var{Rcv}
91will 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
98connection. The call returnes when all data has been acknowledged by
99the 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}
134The number of bytes received but not yet read (what you can \var{Recv}
135without 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
148datagram arrival without outstanding \var{Read} call. The asr has a
149single 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}
157Read a datagram, waiting at most \var{timeout} seconds (-1 is
158indefinite). Returns the data.
159\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}