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