docs/reference/tmpl/lm-connection.sgml
changeset 240 4d512f7e4ce1
parent 140 103227122f45
child 349 3dafc8376e9b
equal deleted inserted replaced
239:b80867c0e10a 240:4d512f7e4ce1
     5 A client connection to the server
     5 A client connection to the server
     6 
     6 
     7 <!-- ##### SECTION Long_Description ##### -->
     7 <!-- ##### SECTION Long_Description ##### -->
     8 <para>
     8 <para>
     9 An example of how to use Loudmouth with the synchronous API.
     9 An example of how to use Loudmouth with the synchronous API.
    10 <informalexample><programlisting><![CDATA[
    10 <informalexample><programlisting>
    11 int
    11 int
    12 main (int argc, char **argv)
    12 main (int argc, char **argv)
    13 {
    13 {
    14         LmConnection *connection;
    14         LmConnection *connection;
    15         GError       *error = NULL;
    15         GError       *error = NULL;
    16         gint          i;
    16         gint          i;
    17 	LmMessage    *m;
    17 	LmMessage    *m;
    18 
    18 
    19         connection = lm_connection_new ("myserver");
    19         connection = lm_connection_new ("myserver");
    20 
    20 
    21         if (!lm_connection_open_and_block (connection, &error)) {
    21         if (!lm_connection_open_and_block (connection, &amp;error)) {
    22                 g_error ("Failed to open: %s\n", error->message);
    22                 g_error ("Failed to open: &percnt;s\n", error->message);
    23         }
    23         }
    24 
    24 
    25 	if (!lm_connection_authenticate_and_block (connection,
    25 	if (!lm_connection_authenticate_and_block (connection,
    26 						   "username", "password", 
    26 						   "username", "password", 
    27 						   "resource",
    27 						   "resource",
    28 						   &error)) {
    28 						   &amp;error)) {
    29 		g_error ("Failed to authenticate: %s\n", error->message);
    29 		g_error ("Failed to authenticate: &percnt;s\n", error->message);
    30 	}
    30 	}
    31 	
    31 	
    32 	m = lm_message_new ("recipient", LM_MESSAGE_TYPE_MESSAGE);
    32 	m = lm_message_new ("recipient", LM_MESSAGE_TYPE_MESSAGE);
    33 	lm_message_node_add_child (m->node, "body", "message");
    33 	lm_message_node_add_child (m->node, "body", "message");
    34 	
    34 	
    35 	if (!lm_connection_send (connection, m, &error)) {
    35 	if (!lm_connection_send (connection, m, &amp;error)) {
    36 		g_error ("Send failed: %s\n", error->message);
    36 		g_error ("Send failed: &percnt;s\n", error->message);
    37 	}
    37 	}
    38 
    38 
    39 	lm_message_unref (m);
    39 	lm_message_unref (m);
    40 
    40 
    41 	lm_connection_close (connection, NULL);
    41 	lm_connection_close (connection, NULL);
    42 	lm_connection_unref (connection);
    42 	lm_connection_unref (connection);
    43 	
    43 	
    44         return 0;
    44         return 0;
    45 }
    45 }
    46 ]]></programlisting></informalexample>
    46 </programlisting></informalexample>
    47 </para>
    47 </para>
    48 
    48 
    49 <!-- ##### SECTION See_Also ##### -->
    49 <!-- ##### SECTION See_Also ##### -->
    50 <para>
    50 <para>
    51 
    51