4
4
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5
<title>GIO Reference Manual: GSocket</title>
6
6
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
7
7
<link rel="home" href="index.html" title="GIO Reference Manual">
8
8
<link rel="up" href="networking.html" title="Low-level network support">
12
12
<link rel="stylesheet" href="style.css" type="text/css">
14
14
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
15
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
17
<td><a accesskey="p" href="networking.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
18
<td><a accesskey="u" href="networking.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
19
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
20
<th width="100%" align="center">GIO Reference Manual</th>
21
<td><a accesskey="n" href="GInetAddress.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
23
<tr><td colspan="5" class="shortcuts">
24
<a href="#GSocket.synopsis" class="shortcut">Top</a>
15
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="10"><tr valign="middle">
16
<td width="100%" align="left">
17
<a href="#" class="shortcut">Top</a>
26
19
<a href="#GSocket.description" class="shortcut">Description</a>
30
23
<a href="#GSocket.implemented-interfaces" class="shortcut">Implemented Interfaces</a>
32
25
<a href="#GSocket.properties" class="shortcut">Properties</a>
27
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
28
<td><a accesskey="u" href="networking.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
29
<td><a accesskey="p" href="networking.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
30
<td><a accesskey="n" href="GInetAddress.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
35
32
<div class="refentry">
36
33
<a name="GSocket"></a><div class="titlepage"></div>
37
34
<div class="refnamediv"><table width="100%"><tr>
675
672
used to initiate connections, though this is not normally required.
678
<em class="parameter"><code>allow_reuse</code></em> should be <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> for server sockets (sockets that you will
679
eventually call <a class="link" href="GSocket.html#g-socket-accept" title="g_socket_accept ()"><code class="function">g_socket_accept()</code></a> on), and <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> for client sockets.
680
(Specifically, if it is <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a>, then <a class="link" href="GSocket.html#g-socket-bind" title="g_socket_bind ()"><code class="function">g_socket_bind()</code></a> will set the
681
<code class="literal">SO_REUSEADDR</code> flag on the socket, allowing it to bind <em class="parameter"><code>address</code></em> even if
682
that address was previously used by another socket that has not yet been
683
fully cleaned-up by the kernel. Failing to set this flag on a server
684
socket may cause the bind call to return <a class="link" href="gio-GIOError.html#G-IO-ERROR-ADDRESS-IN-USE:CAPS"><code class="literal">G_IO_ERROR_ADDRESS_IN_USE</code></a> if
685
the server program is stopped and then immediately restarted.)
675
If <em class="parameter"><code>socket</code></em> is a TCP socket, then <em class="parameter"><code>allow_reuse</code></em> controls the setting
676
of the <code class="literal">SO_REUSEADDR</code> socket option; normally it
677
should be <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> for server sockets (sockets that you will
678
eventually call <a class="link" href="GSocket.html#g-socket-accept" title="g_socket_accept ()"><code class="function">g_socket_accept()</code></a> on), and <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> for client
679
sockets. (Failing to set this flag on a server socket may cause
680
<a class="link" href="GSocket.html#g-socket-bind" title="g_socket_bind ()"><code class="function">g_socket_bind()</code></a> to return <a class="link" href="gio-GIOError.html#G-IO-ERROR-ADDRESS-IN-USE:CAPS"><code class="literal">G_IO_ERROR_ADDRESS_IN_USE</code></a> if the server
681
program is stopped and then immediately restarted.)
684
If <em class="parameter"><code>socket</code></em> is a UDP socket, then <em class="parameter"><code>allow_reuse</code></em> determines whether or
685
not other UDP sockets can be bound to the same address at the same
686
time. In particular, you can have several UDP sockets bound to the
687
same address, and they will all receive all of the multicast and
688
broadcast packets sent to that address. (The behavior of unicast
689
UDP packets to an address with multiple listeners is not defined.)
687
691
<div class="variablelist"><table border="0" class="variablelist">
2311
2315
Gets the broadcast setting on <em class="parameter"><code>socket</code></em>; if <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a>,
2312
2316
it is possible to send packets to broadcast
2313
addresses or receive from broadcast addresses.
2315
2319
<div class="variablelist"><table border="0" class="variablelist">
2337
2341
<pre class="programlisting"><span class="returnvalue">void</span> g_socket_set_broadcast (<em class="parameter"><code><a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> *socket</code></em>,
2338
2342
<em class="parameter"><code><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a> broadcast</code></em>);</pre>
2340
Sets whether <em class="parameter"><code>socket</code></em> should allow sending to and receiving from
2341
broadcast addresses. This is <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> by default.
2344
Sets whether <em class="parameter"><code>socket</code></em> should allow sending to broadcast addresses.
2345
This is <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> by default.
2343
2347
<div class="variablelist"><table border="0" class="variablelist">
2354
2358
<td><p><span class="term"><em class="parameter"><code>broadcast</code></em> :</span></p></td>
2355
<td>whether <em class="parameter"><code>socket</code></em> should allow sending to and receiving
2356
from broadcast addresses</td>
2359
<td>whether <em class="parameter"><code>socket</code></em> should allow sending to broadcast
2783
2787
<td>a <a class="link" href="GInetAddress.html" title="GInetAddress"><span class="type">GInetAddress</span></a> specifying the group address to join.</td>
2790
<td><p><span class="term"><em class="parameter"><code>source_specific</code></em> :</span></p></td>
2792
<a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if source-specific multicast should be used</td>
2786
2795
<td><p><span class="term"><em class="parameter"><code>iface</code></em> :</span></p></td>
2787
2796
<td>Name of the interface to use, or <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. <span class="annotation">[<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
2791
<td><p><span class="term"><em class="parameter"><code>source_specific</code></em> :</span></p></td>
2793
<a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if source-specific multicast should be used</td>
2796
2800
<td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td>
2798
2802
<a href="http://library.gnome.org/devel/glib/unstable/glib-Error-Reporting.html#GError"><span class="type">GError</span></a> for error reporting, or <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to ignore.</td>
2838
2842
<td>a <a class="link" href="GInetAddress.html" title="GInetAddress"><span class="type">GInetAddress</span></a> specifying the group address to leave.</td>
2845
<td><p><span class="term"><em class="parameter"><code>source_specific</code></em> :</span></p></td>
2847
<a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if source-specific multicast was used</td>
2841
2850
<td><p><span class="term"><em class="parameter"><code>iface</code></em> :</span></p></td>
2842
2851
<td>Interface used. <span class="annotation">[<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
2846
<td><p><span class="term"><em class="parameter"><code>source_specific</code></em> :</span></p></td>
2848
<a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if source-specific multicast was used</td>
2851
2855
<td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td>
2853
2857
<a href="http://library.gnome.org/devel/glib/unstable/glib-Error-Reporting.html#GError"><span class="type">GError</span></a> for error reporting, or <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to ignore.</td>
2988
2992
<a name="GSocket--broadcast"></a><h3>The <code class="literal">"broadcast"</code> property</h3>
2989
2993
<pre class="programlisting"> "broadcast" <a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a> : Read / Write</pre>
2991
Whether the socket should allow sending to and receiving from broadcast addresses.
2995
Whether the socket should allow sending to broadcast addresses.
2993
2997
<p>Default value: FALSE</p>
2994
2998
<p class="since">Since 2.32</p>