Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 1 | \section{Built-in module \sectcode{mactcp}} |
| 2 | \bimodindex{mactcp} |
| 3 | \renewcommand{\indexsubitem}{(in module mactcp)} |
| 4 | |
| 5 | This module provides an interface to the Macintosh TCP/IP driver |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 6 | MacTCP\@. There is an accompanying module \code{macdnr} which provides an |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 7 | interface to the name-server (allowing you to translate hostnames to |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 8 | ip-addresses), a module \code{MACTCP} which has symbolic names for |
| 9 | constants constants used by MacTCP and a wrapper module \code{socket} |
| 10 | which mimics the \UNIX{} socket interface (as far as possible). |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 11 | |
| 12 | A complete description of the MacTCP interface can be found in the |
| 13 | Apple MacTCP API documentation. |
| 14 | |
| 15 | \begin{funcdesc}{MTU}{} |
| 16 | Return the Maximum Transmit Unit (the packet size) of the network |
| 17 | interface. |
| 18 | \end{funcdesc} |
| 19 | |
| 20 | \begin{funcdesc}{IPAddr}{} |
| 21 | Return the 32-bit integer IP address of the network interface. |
| 22 | \end{funcdesc} |
| 23 | |
| 24 | \begin{funcdesc}{NetMask}{} |
| 25 | Return the 32-bit integer network mask of the interface. |
| 26 | \end{funcdesc} |
| 27 | |
| 28 | \begin{funcdesc}{TCPCreate}{size} |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 29 | Create a TCP Stream object. \var{size} is the size of the receive |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 30 | buffer, \code{4096} is suggested by various sources. |
| 31 | \end{funcdesc} |
| 32 | |
| 33 | \begin{funcdesc}{UDPCreate}{size, port} |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 34 | Create a UDP stream object. \var{size} is the size of the receive |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 35 | buffer (and, hence, the size of the biggest datagram you can receive |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 36 | on this port). \var{port} is the UDP port number you want to receive |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 37 | datagrams 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 Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 44 | When set to a value different than \code{None} this should point to a |
| 45 | function with two integer parameters:\ an event code and a detail. This |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 46 | function will be called upon network-generated events such as urgent |
| 47 | data arrival. In addition, it is called with eventcode |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 48 | \code{MACTCP.PassiveOpenDone} when a \code{PassiveOpen} completes. This |
| 49 | is a Python addition to the MacTCP semantics. |
| 50 | It is safe to do further calls from the \code{asr}. |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 51 | \end{datadesc} |
| 52 | |
| 53 | \begin{funcdesc}{PassiveOpen}{port} |
| 54 | Wait for an incoming connection on TCP port \var{port} (zero makes the |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 55 | system pick a free port). The call returns immediately, and you should |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 56 | use \var{wait} to wait for completion. You should not issue any method |
| 57 | calls other than |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 58 | \code{wait}, \code{isdone} or \code{GetSockName} before the call |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 59 | completes. |
| 60 | \end{funcdesc} |
| 61 | |
| 62 | \begin{funcdesc}{wait}{} |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 63 | Wait for \code{PassiveOpen} to complete. |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 64 | \end{funcdesc} |
| 65 | |
| 66 | \begin{funcdesc}{isdone}{} |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 67 | Return 1 if a \code{PassiveOpen} has completed. |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 68 | \end{funcdesc} |
| 69 | |
| 70 | \begin{funcdesc}{GetSockName}{} |
| 71 | Return 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 Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 76 | Open an outgoing connection to TCP address \code{(\var{host}, \var{rport})}. Use |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 77 | local port \var{lport} (zero makes the system pick a free port). This |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 78 | call blocks until the connection has been established. |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 79 | \end{funcdesc} |
| 80 | |
| 81 | \begin{funcdesc}{Send}{buf\, push\, urgent} |
| 82 | Send data \var{buf} over the connection. \var{Push} and \var{urgent} |
| 83 | are flags as specified by the TCP standard. |
| 84 | \end{funcdesc} |
| 85 | |
| 86 | \begin{funcdesc}{Rcv}{timeout} |
| 87 | Receive data. The call returns when \var{timeout} seconds have passed |
| 88 | or when (according to the MacTCP documentation) ``a reasonable amount |
| 89 | of data has been received''. The return value is a 3-tuple |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 90 | \code{(\var{data}, \var{urgent}, \var{mark})}. If urgent data is outstanding \code{Rcv} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 91 | will always return that before looking at any normal data. The first |
| 92 | call returning urgent data will have the \var{urgent} flag set, the |
| 93 | last will have the \var{mark} flag set. |
| 94 | \end{funcdesc} |
| 95 | |
| 96 | \begin{funcdesc}{Close}{} |
| 97 | Tell MacTCP that no more data will be transmitted on this |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 98 | connection. The call returns when all data has been acknowledged by |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 99 | the receiving side. |
| 100 | \end{funcdesc} |
| 101 | |
| 102 | \begin{funcdesc}{Abort}{} |
| 103 | Forcibly close both sides of a connection, ignoring outstanding data. |
| 104 | \end{funcdesc} |
| 105 | |
| 106 | \begin{funcdesc}{Status}{} |
| 107 | Return a TCP status object for this stream. |
| 108 | \end{funcdesc} |
| 109 | |
| 110 | \subsection{TCP status objects} |
| 111 | This object has no methods, only some members holding information on |
| 112 | the connection. A complete description of all fields in this objects |
| 113 | can 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} |
| 120 | The integer IP-addresses and port numbers of both endpoints of the |
| 121 | connection. |
| 122 | \end{datadesc} |
| 123 | |
| 124 | \begin{datadesc}{sendWindow} |
| 125 | The current window size. |
| 126 | \end{datadesc} |
| 127 | |
| 128 | \begin{datadesc}{amtUnackedData} |
| 129 | The number of bytes sent but not yet acknowledged. \code{sendWindow - |
| 130 | amtUnackedData} is what you can pass to \code{Send} without blocking. |
| 131 | \end{datadesc} |
| 132 | |
| 133 | \begin{datadesc}{amtUnreadData} |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 134 | The number of bytes received but not yet read (what you can \code{Recv} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 135 | without blocking). |
| 136 | \end{datadesc} |
| 137 | |
| 138 | |
| 139 | |
| 140 | \subsection{UDP stream objects} |
| 141 | Note that, unlike the name suggests, there is nothing stream-like |
| 142 | about UDP. |
| 143 | |
| 144 | \renewcommand{\indexsubitem}{(UDP stream method)} |
| 145 | |
| 146 | \begin{datadesc}{asr} |
| 147 | The asynchronous service routine to be called on events such as |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 148 | datagram arrival without outstanding \code{Read} call. The \code{asr} has a |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 149 | single argument, the event code. |
| 150 | \end{datadesc} |
| 151 | |
| 152 | \begin{datadesc}{port} |
| 153 | A read-only member giving the port number of this UDP stream. |
| 154 | \end{datadesc} |
| 155 | |
| 156 | \begin{funcdesc}{Read}{timeout} |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 157 | Read a datagram, waiting at most \var{timeout} seconds ($-1$ is |
| 158 | indefinite). Return the data. |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 159 | \end{funcdesc} |
| 160 | |
| 161 | \begin{funcdesc}{Write}{host\, port\, buf} |
| 162 | Send \var{buf} as a datagram to IP-address \var{host}, port |
| 163 | \var{port}. |
| 164 | \end{funcdesc} |