<?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.4 $ --> <!-- splitted from ./en/functions/sockets.xml, last change in rev 1.27 --> <refentry id="function.socket-write"> <refnamediv> <refname>socket_write</refname> <refpurpose>Write to a socket</refpurpose> </refnamediv> <refsect1> <title>Description</title> <methodsynopsis> <type>int</type><methodname>socket_write</methodname> <methodparam><type>resource</type><parameter>socket</parameter></methodparam> <methodparam><type>string</type><parameter>buffer</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>length</parameter></methodparam> </methodsynopsis> <para> The function <function>socket_write</function> writes to the socket <parameter>socket</parameter> from <parameter>buffer</parameter>. </para> <para> The optional parameter <parameter>length</parameter> can specify an alternate length of bytes written to the socket. If this length is greater then the buffer length, it is silently truncated to the length of the buffer. </para> <para> Returns the number of bytes successfully written to the socket or &false; one error. The error code can be retrieved with <function>socket_last_error</function>. This code may be passed to <function>socket_strerror</function> to get a textual explanation of the error. </para> <note> <para> <function>socket_write</function> does not necessarily write all bytes from the given buffer. It's valid that, depending on the network buffers etc., only a certain amount of data, even one byte, is written though your buffer is greater. You have to watch out so you don't unintentionally forget to transmit the rest of your data. </para> </note> <note> <para> It is perfectly valid for <function>socket_write</function> to return zero which means no bytes have been written. Be sure to use the <literal>===</literal> operator to check for &false; in case of an error. </para> </note> <para> See also <function>socket_accept</function>, <function>socket_bind</function>, <function>socket_connect</function>, <function>socket_listen</function>, <function>socket_read</function> and <function>socket_strerror</function>. </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t indent-tabs-mode:nil sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->