Description
A UdpSocket represents an open UDP (or datagram) socket. Create a
UdpSocket by calling udp_socket_new() or udp_socket_port_new().
A UdpPacket represents a packet that can be sent or received via a
UdpSocket (or McastSocket). Create a UdpPacket by calling
udp_packet_receive_new or udp_packet_send_new depending on whether you
plan to use this structure to send or receive the packet.
If you are writing a new protocol, you probably want to use TCP, not
UDP.
Details
gnet_udp_socket_new ()
Create and open a new UDP socket with any port.
gnet_udp_socket_new_interface ()
Create and open a new UDP socket bound to the specified interface.
If the interface address's port number is 0, the OS will choose
the port.
gnet_udp_socket_port_new ()
Create and open a new UDP socket with a specific port.
gnet_udp_socket_delete ()
Close and delete a UDP socket.
gnet_udp_socket_ref ()
Increment the reference counter of the GUdpSocket.
gnet_udp_socket_unref ()
Remove a reference from the GUdpSocket. When reference count
reaches 0, the socket is deleted.
struct GUdpPacket
struct GUdpPacket
{
gint8* data;
guint length;
GInetAddr* addr;
}; |
gnet_udp_socket_receive ()
Receive a packet using the UDP socket.
gnet_udp_socket_has_packet ()
gboolean gnet_udp_socket_has_packet (const GUdpSocket *s); |
Test if the socket has a receive packet. It's strongly
recommended that you use a GIOChannel with a read watch instead
of this function.
gnet_udp_socket_get_iochannel ()
GIOChannel* gnet_udp_socket_get_iochannel (GUdpSocket *socket); |
Get a GIOChannel from the GUdpSocket.
THIS IS NOT A NORMAL GIOCHANNEL - DO NOT READ OR WRITE WITH IT.
Use the channel with g_io_add_watch() to do asynchronous IO (so if
you do not want to do asynchronous IO, you do not need the
channel). If you can read from the channel, use
gnet_udp_socket_receive() to read a packet. If you can write to
the channel, use gnet_udp_socket_send() to write a packet.
There is one channel for every socket. This function refs the
channel before returning it. You should unref the channel when
you are done with it. However, you should not close the channel -
this is done when you delete the socket.
gnet_udp_socket_get_ttl ()
gint gnet_udp_socket_get_ttl (const GUdpSocket *us); |
Get the TTL of the UDP socket. TTL is the Time To Live - the
number of hops outgoing packets will travel. This is useful for
resource discovery; for most programs, you don't need to use it.
gnet_udp_socket_set_ttl ()
gint gnet_udp_socket_set_ttl (GUdpSocket *us,
int val); |
Set the TTL of the UDP socket.
gnet_udp_socket_get_mcast_ttl ()
gint gnet_udp_socket_get_mcast_ttl (const GUdpSocket *us); |
Get the TTL for outgoing multicast packests. TTL is the Time To
Live - the number of hops outgoing packets will travel. The
default TTL is usually 1, which mean outgoing packets will only
travel as far as the local subnet.
This reason this function is in the UDP module is that UdpSocket's
(as well as McastSocket's) can be used to sent to multicast
groups.
Here's a handy table. Note that the "meaning" really doesn't mean
anything. The mcast people basically just gave them these names
because they sounded cool.
<table>
<title>TTL and "meaning"</title>
<tgroup cols=2 align=left>
<thead>
<row>
<entry>TTL</entry>
<entry>meaning</entry>
</row>
</thead>
<tbody>
<row>
<entry>0</entry>
<entry>node local</entry>
</row>
<row>
<entry>1</entry>
<entry>link local</entry>
</row>
<row>
<entry>2-32</entry>
<entry>site local</entry>
</row>
<row>
<entry>33-64</entry>
<entry>region local</entry>
</row>
<row>
<entry>65-128</entry>
<entry>continent local</entry>
</row>
<row>
<entry>129-255</entry>
<entry>unrestricted (global)</entry>
</row>
</tbody>
</table>
gnet_udp_socket_set_mcast_ttl ()
gint gnet_udp_socket_set_mcast_ttl (GUdpSocket *us,
gint val); |
Set the TTL for outgoing multicast packets.
This reason this function is in the UDP module is that UdpSocket's
(as well as McastSocket's) can be used to sent to multicast
groups.
gnet_udp_packet_receive_new ()
GUdpPacket* gnet_udp_packet_receive_new (guint8 *data,
gint length); |
Create a packet for receiving. data is a shallow copy and must
be deallocated by the caller if necessary when appropriate.
gnet_udp_packet_send_new ()
Create a packet for sending. The fields of the new packet are
public. data and addr are shallow copies and must be
deallocated by the caller if necessary when appropriate.
gnet_udp_packet_delete ()
Delete a UDP packet. The fields "data" and "addr" are not deleted
and should be deallocated by the programmer if necessary when
appropriate.