Fred Drake | c817e27 | 1998-08-10 18:40:22 +0000 | [diff] [blame] | 1 | \section{\module{mactcp} --- |
Fred Drake | f6863c1 | 1999-03-02 16:37:17 +0000 | [diff] [blame] | 2 | The MacTCP interfaces} |
| 3 | |
Fred Drake | fe7f3bc | 1998-07-23 17:55:31 +0000 | [diff] [blame] | 4 | \declaremodule{builtin}{mactcp} |
Fred Drake | f6863c1 | 1999-03-02 16:37:17 +0000 | [diff] [blame] | 5 | \platform{Mac} |
Fred Drake | fe7f3bc | 1998-07-23 17:55:31 +0000 | [diff] [blame] | 6 | \modulesynopsis{The MacTCP interfaces.} |
| 7 | |
Guido van Rossum | 470be14 | 1995-03-17 16:07:09 +0000 | [diff] [blame] | 8 | |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 9 | This module provides an interface to the Macintosh TCP/IP driver% |
Fred Drake | b6d45c6 | 1998-11-25 19:55:47 +0000 | [diff] [blame] | 10 | \index{MacTCP} MacTCP. There is an accompanying module, |
Fred Drake | f6863c1 | 1999-03-02 16:37:17 +0000 | [diff] [blame] | 11 | \refmodule{macdnr}\refbimodindex{macdnr}, which provides an interface |
| 12 | to the name-server (allowing you to translate hostnames to IP |
| 13 | addresses), a module \module{MACTCPconst}\refstmodindex{MACTCPconst} |
| 14 | which has symbolic names for constants constants used by MacTCP. Since |
| 15 | the built-in module \module{socket}\refbimodindex{socket} is also |
| 16 | available on the Macintosh it is usually easier to use sockets instead |
| 17 | of the Macintosh-specific MacTCP API. |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 18 | |
| 19 | A complete description of the MacTCP interface can be found in the |
| 20 | Apple MacTCP API documentation. |
| 21 | |
| 22 | \begin{funcdesc}{MTU}{} |
| 23 | Return the Maximum Transmit Unit (the packet size) of the network |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 24 | interface.\index{Maximum Transmit Unit} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 25 | \end{funcdesc} |
| 26 | |
| 27 | \begin{funcdesc}{IPAddr}{} |
| 28 | Return the 32-bit integer IP address of the network interface. |
| 29 | \end{funcdesc} |
| 30 | |
| 31 | \begin{funcdesc}{NetMask}{} |
| 32 | Return the 32-bit integer network mask of the interface. |
| 33 | \end{funcdesc} |
| 34 | |
| 35 | \begin{funcdesc}{TCPCreate}{size} |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 36 | 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] | 37 | buffer, \code{4096} is suggested by various sources. |
| 38 | \end{funcdesc} |
| 39 | |
| 40 | \begin{funcdesc}{UDPCreate}{size, port} |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 41 | 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] | 42 | 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] | 43 | 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] | 44 | datagrams on, a value of zero will make MacTCP select a free port. |
| 45 | \end{funcdesc} |
| 46 | |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 47 | |
Guido van Rossum | 470be14 | 1995-03-17 16:07:09 +0000 | [diff] [blame] | 48 | \subsection{TCP Stream Objects} |
| 49 | |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 50 | \begin{memberdesc}[TCP Stream]{asr} |
| 51 | \index{asynchronous service routine} |
| 52 | \index{service routine, asynchronous} |
| 53 | When set to a value different than \code{None} this should refer to a |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 54 | function with two integer parameters:\ an event code and a detail. This |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 55 | function will be called upon network-generated events such as urgent |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 56 | data arrival. Macintosh documentation calls this the |
| 57 | \dfn{asynchronous service routine}. In addition, it is called with |
Fred Drake | f6863c1 | 1999-03-02 16:37:17 +0000 | [diff] [blame] | 58 | eventcode \code{MACTCP.PassiveOpenDone} when a \method{PassiveOpen()} |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 59 | completes. This is a Python addition to the MacTCP semantics. |
| 60 | It is safe to do further calls from \var{asr}. |
| 61 | \end{memberdesc} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 62 | |
Guido van Rossum | 470be14 | 1995-03-17 16:07:09 +0000 | [diff] [blame] | 63 | |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 64 | \begin{methoddesc}[TCP Stream]{PassiveOpen}{port} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 65 | 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] | 66 | system pick a free port). The call returns immediately, and you should |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 67 | use \method{wait()} to wait for completion. You should not issue any method |
| 68 | calls other than \method{wait()}, \method{isdone()} or |
| 69 | \method{GetSockName()} before the call completes. |
| 70 | \end{methoddesc} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 71 | |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 72 | \begin{methoddesc}[TCP Stream]{wait}{} |
Fred Drake | f6863c1 | 1999-03-02 16:37:17 +0000 | [diff] [blame] | 73 | Wait for \method{PassiveOpen()} to complete. |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 74 | \end{methoddesc} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 75 | |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 76 | \begin{methoddesc}[TCP Stream]{isdone}{} |
Fred Drake | f6863c1 | 1999-03-02 16:37:17 +0000 | [diff] [blame] | 77 | Return \code{1} if a \method{PassiveOpen()} has completed. |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 78 | \end{methoddesc} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 79 | |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 80 | \begin{methoddesc}[TCP Stream]{GetSockName}{} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 81 | Return the TCP address of this side of a connection as a 2-tuple |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 82 | \code{(\var{host}, \var{port})}, both integers. |
| 83 | \end{methoddesc} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 84 | |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 85 | \begin{methoddesc}[TCP Stream]{ActiveOpen}{lport, host, rport} |
| 86 | Open an outgoing connection to TCP address \code{(\var{host}, |
| 87 | \var{rport})}. Use |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 88 | 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] | 89 | call blocks until the connection has been established. |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 90 | \end{methoddesc} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 91 | |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 92 | \begin{methoddesc}[TCP Stream]{Send}{buf, push, urgent} |
| 93 | Send data \var{buf} over the connection. \var{push} and \var{urgent} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 94 | are flags as specified by the TCP standard. |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 95 | \end{methoddesc} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 96 | |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 97 | \begin{methoddesc}[TCP Stream]{Rcv}{timeout} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 98 | Receive data. The call returns when \var{timeout} seconds have passed |
| 99 | or when (according to the MacTCP documentation) ``a reasonable amount |
| 100 | of data has been received''. The return value is a 3-tuple |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 101 | \code{(\var{data}, \var{urgent}, \var{mark})}. If urgent data is |
| 102 | outstanding \code{Rcv} will always return that before looking at any |
| 103 | normal data. The first call returning urgent data will have the |
| 104 | \var{urgent} flag set, the last will have the \var{mark} flag set. |
| 105 | \end{methoddesc} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 106 | |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 107 | \begin{methoddesc}[TCP Stream]{Close}{} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 108 | Tell MacTCP that no more data will be transmitted on this |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 109 | connection. The call returns when all data has been acknowledged by |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 110 | the receiving side. |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 111 | \end{methoddesc} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 112 | |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 113 | \begin{methoddesc}[TCP Stream]{Abort}{} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 114 | Forcibly close both sides of a connection, ignoring outstanding data. |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 115 | \end{methoddesc} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 116 | |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 117 | \begin{methoddesc}[TCP Stream]{Status}{} |
Guido van Rossum | 470be14 | 1995-03-17 16:07:09 +0000 | [diff] [blame] | 118 | Return a TCP status object for this stream giving the current status |
| 119 | (see below). |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 120 | \end{methoddesc} |
| 121 | |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 122 | |
Guido van Rossum | 470be14 | 1995-03-17 16:07:09 +0000 | [diff] [blame] | 123 | \subsection{TCP Status Objects} |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 124 | |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 125 | This object has no methods, only some members holding information on |
| 126 | the connection. A complete description of all fields in this objects |
| 127 | can be found in the Apple documentation. The most interesting ones are: |
| 128 | |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 129 | \begin{memberdesc}[TCP Status]{localHost} |
| 130 | \memberline{localPort} |
| 131 | \memberline{remoteHost} |
| 132 | \memberline{remotePort} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 133 | The integer IP-addresses and port numbers of both endpoints of the |
| 134 | connection. |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 135 | \end{memberdesc} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 136 | |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 137 | \begin{memberdesc}[TCP Status]{sendWindow} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 138 | The current window size. |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 139 | \end{memberdesc} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 140 | |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 141 | \begin{memberdesc}[TCP Status]{amtUnackedData} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 142 | The number of bytes sent but not yet acknowledged. \code{sendWindow - |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 143 | amtUnackedData} is what you can pass to \method{Send()} without |
| 144 | blocking. |
| 145 | \end{memberdesc} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 146 | |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 147 | \begin{memberdesc}[TCP Status]{amtUnreadData} |
| 148 | The number of bytes received but not yet read (what you can |
| 149 | \method{Recv()} without blocking). |
| 150 | \end{memberdesc} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 151 | |
| 152 | |
| 153 | |
Guido van Rossum | 470be14 | 1995-03-17 16:07:09 +0000 | [diff] [blame] | 154 | \subsection{UDP Stream Objects} |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 155 | |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 156 | Note that, unlike the name suggests, there is nothing stream-like |
| 157 | about UDP. |
| 158 | |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 159 | |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 160 | \begin{memberdesc}[UDP Stream]{asr} |
| 161 | \index{asynchronous service routine} |
| 162 | \index{service routine, asynchronous} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 163 | The asynchronous service routine to be called on events such as |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 164 | datagram arrival without outstanding \code{Read} call. The \var{asr} |
| 165 | has a single argument, the event code. |
| 166 | \end{memberdesc} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 167 | |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 168 | \begin{memberdesc}[UDP Stream]{port} |
| 169 | A read-only member giving the port number of this UDP Stream. |
| 170 | \end{memberdesc} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 171 | |
Guido van Rossum | 470be14 | 1995-03-17 16:07:09 +0000 | [diff] [blame] | 172 | |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 173 | \begin{methoddesc}[UDP Stream]{Read}{timeout} |
Guido van Rossum | f259efe | 1997-11-25 01:00:40 +0000 | [diff] [blame] | 174 | Read a datagram, waiting at most \var{timeout} seconds (-1 is |
Guido van Rossum | 470be14 | 1995-03-17 16:07:09 +0000 | [diff] [blame] | 175 | infinite). Return the data. |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 176 | \end{methoddesc} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 177 | |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 178 | \begin{methoddesc}[UDP Stream]{Write}{host, port, buf} |
Jack Jansen | b721ef1 | 1995-03-01 14:54:30 +0000 | [diff] [blame] | 179 | Send \var{buf} as a datagram to IP-address \var{host}, port |
| 180 | \var{port}. |
Fred Drake | 6188592 | 1998-04-03 07:16:46 +0000 | [diff] [blame] | 181 | \end{methoddesc} |