<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--Converted with LaTeX2HTML 98.2 beta6 (August 14th, 1998)
original version by:  Nikos Drakos, CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>4.1 Connection Objects </TITLE>
<META NAME="description" CONTENT="4.1 Connection Objects ">
<META NAME="keywords" CONTENT="mac">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" HREF="mac.css">
<LINK REL="previous" HREF="module-ctb.html">
<LINK REL="up" HREF="module-ctb.html">
<LINK REL="next" HREF="module-macconsole.html">
</HEAD>
<BODY bgcolor="#ffffff">
<div class=navigation>
<table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="module-macconsole.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="module-ctb.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="module-ctb.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Macintosh Library Modules</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="module-macconsole.html">5. macconsole  </A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="module-ctb.html">4. ctb  </A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="module-ctb.html">4. ctb  </A></span>
<br><hr></div>
<!--End of Navigation Panel-->

<H2><A NAME="SECTION002410000000000000000"></A>
<BR>
4.1 Connection Objects 
</H2>

<P>
For all connection methods that take a <var>timeout</var> argument, a value
of <tt>-1</tt> is indefinite, meaning that the command runs to completion.

<P>
<dl><dt><b><a name="l2h-19"><tt class=member>callback</tt></a></b>
<dd>
If this member is set to a value other than <tt>None</tt> it should point
to a function accepting a single argument (the connection
object). This will make all connection object methods work
asynchronously, with the callback routine being called upon
completion.

<P>
<i>Note:</i> for reasons beyond my understanding the callback routine
is currently never called. You are advised against using asynchronous
calls for the time being.
</dl>

<P>
<dl><dt><b><a name="l2h-20"><tt class=method>Open</tt></a></b> (<var>timeout</var>)
<dd>
Open an outgoing connection, waiting at most <var>timeout</var> seconds for
the connection to be established.
</dl>

<P>
<dl><dt><b><a name="l2h-21"><tt class=method>Listen</tt></a></b> (<var>timeout</var>)
<dd>
Wait for an incoming connection. Stop waiting after <var>timeout</var>
seconds. This call is only meaningful to some tools.
</dl>

<P>
<dl><dt><b><a name="l2h-22"><tt class=method>accept</tt></a></b> (<var>yesno</var>)
<dd>
Accept (when <var>yesno</var> is non-zero) or reject an incoming call after
<tt class=method>Listen()</tt> returned.
</dl>

<P>
<dl><dt><b><a name="l2h-23"><tt class=method>Close</tt></a></b> (<var>timeout, now</var>)
<dd>
Close a connection. When <var>now</var> is zero, the close is orderly
(i.e. outstanding output is flushed, etc.) with a timeout of
<var>timeout</var> seconds. When <var>now</var> is non-zero the close is
immediate, discarding output.
</dl>

<P>
<dl><dt><b><a name="l2h-24"><tt class=method>Read</tt></a></b> (<var>len, chan, timeout</var>)
<dd>
Read <var>len</var> bytes, or until <var>timeout</var> seconds have passed, from 
the channel <var>chan</var> (which is one of <tt class=constant>cmData</tt>,
<tt class=constant>cmCntl</tt> or <tt class=constant>cmAttn</tt>). Return a 2-tuple: the data
read and the end-of-message flag, <tt class=constant>cmFlagsEOM</tt>.
</dl>

<P>
<dl><dt><b><a name="l2h-25"><tt class=method>Write</tt></a></b> (<var>buf, chan, timeout, eom</var>)
<dd>
Write <var>buf</var> to channel <var>chan</var>, aborting after <var>timeout</var>
seconds. When <var>eom</var> has the value <tt class=constant>cmFlagsEOM</tt>, an
end-of-message indicator will be written after the data (if this
concept has a meaning for this communication tool). The method returns
the number of bytes written.
</dl>

<P>
<dl><dt><b><a name="l2h-26"><tt class=method>Status</tt></a></b> ()
<dd>
Return connection status as the 2-tuple <tt>(<var>sizes</var>,
<var>flags</var>)</tt>. <var>sizes</var> is a 6-tuple giving the actual buffer sizes used
(see <tt class=function>CMNew()</tt>), <var>flags</var> is a set of bits describing the state
of the connection.
</dl>

<P>
<dl><dt><b><a name="l2h-27"><tt class=method>GetConfig</tt></a></b> ()
<dd>
Return the configuration string of the communication tool. These
configuration strings are tool-dependent, but usually easily parsed
and modified.
</dl>

<P>
<dl><dt><b><a name="l2h-28"><tt class=method>SetConfig</tt></a></b> (<var>str</var>)
<dd>
Set the configuration string for the tool. The strings are parsed
left-to-right, with later values taking precedence. This means
individual configuration parameters can be modified by simply appending
something like <tt>'baud 4800'</tt> to the end of the string returned by
<tt class=method>GetConfig()</tt> and passing that to this method. The method returns
the number of characters actually parsed by the tool before it
encountered an error (or completed successfully).
</dl>

<P>
<dl><dt><b><a name="l2h-29"><tt class=method>Choose</tt></a></b> ()
<dd>
Present the user with a dialog to choose a communication tool and
configure it. If there is an outstanding connection some choices (like
selecting a different tool) may cause the connection to be
aborted. The return value (one of the <tt class=constant>choose*</tt> constants) will
indicate this.
</dl>

<P>
<dl><dt><b><a name="l2h-30"><tt class=method>Idle</tt></a></b> ()
<dd>
Give the tool a chance to use the processor. You should call this
method regularly.
</dl>

<P>
<dl><dt><b><a name="l2h-31"><tt class=method>Abort</tt></a></b> ()
<dd>
Abort an outstanding asynchronous <tt class=method>Open()</tt> or <tt class=method>Listen()</tt>.
</dl>

<P>
<dl><dt><b><a name="l2h-32"><tt class=method>Reset</tt></a></b> ()
<dd>
Reset a connection. Exact meaning depends on the tool.
</dl>

<P>
<dl><dt><b><a name="l2h-33"><tt class=method>Break</tt></a></b> (<var>length</var>)
<dd>
Send a break. Whether this means anything, what it means and
interpretation of the <var>length</var> parameter depends on the tool in
use.
</dl><p>
<div class=navigation><hr><table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="module-macconsole.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="module-ctb.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="module-ctb.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Macintosh Library Modules</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="module-macconsole.html">5. macconsole  </A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="module-ctb.html">4. ctb  </A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="module-ctb.html">4. ctb  </A></span>
</div>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>Send comments on this document to <a href="mailto:python-docs@python.org">python-docs@python.org</a>.
</ADDRESS>
</BODY>
</HTML>
