Keywords: mac

## 2.10.1 TCP Stream Objects

`asr`
  When set to a value different than `None` this should refer to a function with two integer parameters: an event code and a detail. This function will be called upon network-generated events such as urgent data arrival. Macintosh documentation calls this the asynchronous service routine. In addition, it is called with eventcode `MACTCP.PassiveOpenDone` when a `PassiveOpen()` completes. This is a Python addition to the MacTCP semantics. It is safe to do further calls from asr.

`PassiveOpen` (port)
  Wait for an incoming connection on TCP port port (zero makes the system pick a free port). The call returns immediately, and you should use `wait()` to wait for completion. You should not issue any method calls other than `wait()`, `isdone()` or `GetSockName()` before the call completes.

`wait` ()
  Wait for `PassiveOpen()` to complete.

`isdone` ()
  Return `1` if a `PassiveOpen()` has completed.

`GetSockName` ()
  Return the TCP address of this side of a connection as a 2-tuple `(host, port)`, both integers.

`ActiveOpen` (lport, host, rport)
  Open an outgoing connection to TCP address `(host, rport)`. Use local port lport (zero makes the system pick a free port). This call blocks until the connection has been established.

`Send` (buf, push, urgent)
  Send data buf over the connection. push and urgent are flags as specified by the TCP standard.

`Rcv` (timeout)
  Receive data. The call returns when timeout seconds have passed or when (according to the MacTCP documentation) ``a reasonable amount of data has been received''. The return value is a 3-tuple `(data, urgent, mark)`. If urgent data is outstanding `Rcv` will always return that before looking at any normal data. The first call returning urgent data will have the urgent flag set, the last will have the mark flag set.

`Close` ()
  Tell MacTCP that no more data will be transmitted on this connection. The call returns when all data has been acknowledged by the receiving side.

`Abort` ()
  Forcibly close both sides of a connection, ignoring outstanding data.

`Status` ()
  Return a TCP status object for this stream giving the current status (see below).