<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.zmqcontext.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'de',
  ),
  'this' => 
  array (
    0 => 'zmqcontext.getsocket.php',
    1 => 'ZMQContext::getSocket',
    2 => 'Create a new socket',
  ),
  'up' => 
  array (
    0 => 'class.zmqcontext.php',
    1 => 'ZMQContext',
  ),
  'prev' => 
  array (
    0 => 'zmqcontext.getopt.php',
    1 => 'ZMQContext::getOpt',
  ),
  'next' => 
  array (
    0 => 'zmqcontext.ispersistent.php',
    1 => 'ZMQContext::isPersistent',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/zmq/zmqcontext/getsocket.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="zmqcontext.getsocket" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ZMQContext::getSocket</h1>
  <p class="verinfo">(PECL zmq &gt;= 0.5.0)</p><p class="refpurpose"><span class="refname">ZMQContext::getSocket</span> &mdash; <span class="dc-title">Create a new socket</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-zmqcontext.getsocket-description">
  <h3 class="title">Beschreibung</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>ZMQContext::getSocket</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$type</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$persistent_id</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>, <span class="methodparam"><span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span> <code class="parameter">$on_new_socket</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><a href="class.zmqsocket.php" class="type ZMQSocket">ZMQSocket</a></span></div>

  <p class="para rdfs-comment">
   Shortcut for creating new sockets from the context. If the context is not persistent the <code class="parameter">persistent_id</code> 
   parameter is ignored and the socket falls back to being non-persistent. The <code class="parameter">on_new_socket</code> is called only
   when a new underlying socket structure is created.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-zmqcontext.getsocket-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">type</code></dt>
     <dd>
      <p class="para">
       <strong><code><a href="class.zmq.php#zmq.constants.socket-pair">ZMQ::SOCKET_<span class="replaceable">*</span></a></code></strong> constant to specify socket type.
      </p>
     </dd>
    
    
     <dt><code class="parameter">persistent_id</code></dt>
     <dd>
      <p class="para">
       If <code class="parameter">persistent_id</code> is specified the socket will be persisted over multiple requests.
      </p>
     </dd>
    
    
     <dt><code class="parameter">on_new_socket</code></dt>
     <dd>
      <p class="para">
       Callback function, which is executed when a new socket structure is created. This function does not get invoked
       if the underlying persistent connection is re-used. The callback takes ZMQSocket and persistent_id as two arguments.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-zmqcontext.getsocket-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="para">
   Returns a <span class="classname"><a href="class.zmqsocket.php" class="classname">ZMQSocket</a></span> object.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-zmqcontext.getsocket-errors">
  <h3 class="title">Fehler/Exceptions</h3>
  <p class="para">
   Throws <span class="classname"><strong class="classname">ZMQSocketException</strong></span> on error.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-zmqcontext.getsocket-examples">
 <h3 class="title">Beispiele</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Beispiel #1 A <span class="function"><strong>ZMQContext()</strong></span> example</strong></p>
    <div class="example-contents"><p>
     Basic usage
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/* Allocate a new context */<br /></span><span style="color: #0000BB">$context </span><span style="color: #007700">= new </span><span style="color: #0000BB">ZMQContext</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/* Create a new socket */<br /></span><span style="color: #0000BB">$socket </span><span style="color: #007700">= </span><span style="color: #0000BB">$context</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getSocket</span><span style="color: #007700">(</span><span style="color: #0000BB">ZMQ</span><span style="color: #007700">::</span><span style="color: #0000BB">SOCKET_REQ</span><span style="color: #007700">, </span><span style="color: #DD0000">'my sock'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Connect the socket */<br /></span><span style="color: #0000BB">$socket</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"tcp://example.com:1234"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Send a request */<br /></span><span style="color: #0000BB">$socket</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">send</span><span style="color: #007700">(</span><span style="color: #DD0000">"Hello there"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Receive back the response */<br /></span><span style="color: #0000BB">$message </span><span style="color: #007700">= </span><span style="color: #0000BB">$socket</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">recv</span><span style="color: #007700">();<br />echo </span><span style="color: #DD0000">"Received message: </span><span style="color: #007700">{</span><span style="color: #0000BB">$message</span><span style="color: #007700">}</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


</div><?php manual_footer($setup); ?>