GNet Network Library Reference Manual | |||
---|---|---|---|
<<< Previous Page | Home | Up | Next Page >>> |
A UdpSocket represents an open UDP (or datagram) socket. Create a
UdpSocket by calling
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.
struct GUdpSocket { gint sockfd; /* private */ struct sockaddr sa; /* private (Why not an InetAddr?) */ guint ref_count; GIOChannel* iochannel; }; |
struct GUdpPacket { gint8* data; guint length; GInetAddr* addr; }; |
GUdpPacket is a simple helper struct. Its fields are public. The fields 'data' and 'addr' must be deallocated by the programmer if necessary when appropriate.
GUdpSocket* gnet_udp_socket_new (void); |
Create and open a new UDP socket with any port.
GUdpSocket* gnet_udp_socket_port_new ( |
Create and open a new UDP socket with a specific port.
GUdpSocket* gnet_udp_socket_new_interface (const GInetAddr *iface); |
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.
void gnet_udp_socket_ref (GUdpSocket *s); |
Increment the reference counter of the GUdpSocket.
void gnet_udp_socket_unref (GUdpSocket *s); |
Remove a reference from the GUdpSocket. When reference count reaches 0, the socket is deleted.
|
Send the packet using the GUdpSocket.
|
Receive a packet using the UDP socket.
|
Test if the socket has a receive packet. It's strongly
recommended that you use a
|
Get a
THIS IS NOT A NORMAL GIOCHANNEL - DO NOT READ OR WRITE WITH IT.
Use the channel with
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.
|
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.
|
Set the TTL of the UDP socket.
|
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>
|
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.
GUdpPacket* gnet_udp_packet_receive_new ( |
Create a packet for receiving. data is a shallow copy and must be deallocated by the caller if necessary when appropriate.
GUdpPacket* 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.
void gnet_udp_packet_delete (GUdpPacket *packet); |
Delete a UDP packet. The fields "data" and "addr" are not deleted and should be deallocated by the programmer if necessary when appropriate.