Gnet Network Library Reference Manual
<<< Previous Page | Home | Up | Next Page >>>

# Multicast module

## Name

Multicast module -- Multicast functions.

## Synopsis

    GMcastSocket* gnet_mcast_socket_new         (void);
    GMcastSocket* gnet_mcast_socket_port_new    (gint port);
    GMcastSocket* gnet_mcast_socket_inetaddr_new
                                                (GInetAddr *ia);
    void        gnet_mcast_socket_delete        (GMcastSocket *ms);
    void        gnet_mcast_socket_ref           (GMcastSocket *s);
    void        gnet_mcast_socket_unref         (GMcastSocket *s);
    gint        gnet_mcast_socket_join_group    (GMcastSocket *ms,
                                                 GInetAddr *ia);
    gint        gnet_mcast_socket_leave_group   (GMcastSocket *ms,
                                                 GInetAddr *ia);
    gint        gnet_mcast_socket_send          (const GMcastSocket *ms,
                                                 const GUdpPacket *packet);
    gint        gnet_mcast_socket_receive       (const GMcastSocket *ms,
                                                 GUdpPacket *packet);
    gboolean    gnet_mcast_socket_has_packet    (const GMcastSocket *s);
    gint        gnet_mcast_socket_is_loopback   (GMcastSocket *ms);
    gint        gnet_mcast_socket_set_loopback  (GMcastSocket *ms,
                                                 gint b);
    #define     gnet_mcast_socket_to_udp_socket (MS)

## Description

McastSocket represents a multicast socket. Currently, this supports only IP multicast. An McastSocket is a "child" of a UdpSocket. You can cast a pointer to a McastSocket to a pointer to a UdpSocket and then use the UDP functions.

## Details

### gnet_mcast_socket_new ()

    GMcastSocket* gnet_mcast_socket_new         (void);

Create a new multicast socket with any available port. Use this constructor when you are creating a new group and the port number doesn't matter. If you want to receive packets from the group, you will have to join it next.

Returns : | a new GMcastSocket, or NULL if there was a failure.

### gnet_mcast_socket_port_new ()

    GMcastSocket* gnet_mcast_socket_port_new    (gint port);

Create a new multicast socket with the given port. If you know the port of the group you will join, use this constructor. If you want to receive packets from the group, you will have to join it, using the full address, next.

`port` : | Port for the GMcastSocket.
Returns : | a new GMcastSocket, or NULL if there was a failure.

### gnet_mcast_socket_inetaddr_new ()

    GMcastSocket* gnet_mcast_socket_inetaddr_new
                                                (GInetAddr *ia);

Create a new multicast socket with the GInetAddr. If you know the GInetAddr of the group you will join, use this constructor. If you want to receive packets from the group, you will have to join it next.

`ia` : | GInetAddr of the multicast group.
Returns : | a new GMcastSocket, or NULL if there was a failure.

### gnet_mcast_socket_delete ()

    void        gnet_mcast_socket_delete        (GMcastSocket *ms);

Close and delete a multicast socket.

`ms` : | GMcastSocket to delete.

### gnet_mcast_socket_ref ()

    void        gnet_mcast_socket_ref           (GMcastSocket *s);

Increment the reference counter of the GMcastSocket.

`s` : | GMcastSocket to reference

### gnet_mcast_socket_unref ()

    void        gnet_mcast_socket_unref         (GMcastSocket *s);

Remove a reference from the GMcastSocket. When reference count reaches 0, the socket is deleted.

`s` : | GMcastSocket to unreference

### gnet_mcast_socket_join_group ()

    gint        gnet_mcast_socket_join_group    (GMcastSocket *ms,
                                                 GInetAddr *ia);

Join the multicast group using the multicast socket. You should only join one group per socket.

`ms` : | GMcastSocket to use.
`ia` : | Address of the group.
Returns : | 0 on success.

### gnet_mcast_socket_leave_group ()

    gint        gnet_mcast_socket_leave_group   (GMcastSocket *ms,
                                                 GInetAddr *ia);

Leave the mulitcast group.

`ms` : | GMcastSocket to use.
`ia` : | Address of the group to leave.
Returns : | 0 on success.

### gnet_mcast_socket_send ()

    gint        gnet_mcast_socket_send          (const GMcastSocket *ms,
                                                 const GUdpPacket *packet);

Send the packet using the multicast socket.

`ms` : | GMcastSocket to use to send.
`packet` : | Packet to send.
Returns : | 0 if successful.

### gnet_mcast_socket_receive ()

    gint        gnet_mcast_socket_receive       (const GMcastSocket *ms,
                                                 GUdpPacket *packet);

Receive a packet using the mcast socket.

`ms` : | GMcastSocket to receive from.
`packet` : | Packet to receive.
Returns : | the number of bytes received, -1 if unsuccessful.

### gnet_mcast_socket_has_packet ()

    gboolean    gnet_mcast_socket_has_packet    (const GMcastSocket *s);

Test if the socket has a receive packet.

`s` : | GMcastSocket to check
Returns : | TRUE if there is packet waiting, FALSE otherwise.

### gnet_mcast_socket_is_loopback ()

    gint        gnet_mcast_socket_is_loopback   (GMcastSocket *ms);

Check if the multicast socket has loopback enabled. If loopback is enabled, you receive all the packets you send. Most people don't want this.

`ms` : | GMcastSocket to check.
Returns : | 0 if loopback is disabled.

### gnet_mcast_socket_set_loopback ()

    gint        gnet_mcast_socket_set_loopback  (GMcastSocket *ms,
                                                 gint b);

Turn the loopback on or off. If loopback is on, when the process sends a packet, it will automatically be looped back to the host. If it is off, not only will this the process not receive datagrams it sends, other processes on the host will not receive its packets.

`ms` : | GMcastSocket to use.
`b` : | Value to set it to (0 or 1)
Returns : | 0 if successful.

### gnet_mcast_socket_to_udp_socket()

    #define gnet_mcast_socket_to_udp_socket(MS) ((GUdpSocket*) (MS))

`MS` : |

<<< Previous Page | Home | Up | Next Page >>>
Internet address module | TCP module