glib network connection example

做~自己de王妃 提交于 2019-12-10 08:57:21

问题


Can you advice some network connection example made with glib/gio libraries. There is quite a good reference manual, but no full example even for basic things.

It will be used for simple sending and receiving files as a part of program.


回答1:


How about like this? There is similar question at Fetch a file from web: in GTK using C

#include <gio/gio.h>

int main()
{
        const gchar *uri = "https://stackoverflow.com/questions/5758770/";
        GFile *in;
        GFile *out;
        GError *error = NULL;
        gboolean ret;

        g_type_init();

        in = g_file_new_for_uri(uri);
        out = g_file_new_for_path("/tmp/a");

        ret = g_file_copy(in, out, G_FILE_COPY_OVERWRITE,
                          NULL, NULL, NULL, &error);
        if (!ret)
                g_message("%s", error->message);

        return 0;
}


来源:https://stackoverflow.com/questions/5758770/glib-network-connection-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!