Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4092910
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:33:05+00:00 2026-05-20T19:33:05+00:00

dude here im gonna create client and combine with GIO Channel, and after i

  • 0

dude here im gonna create client and combine with GIO Channel, and after i put it all together, it seems appears to work on socket, but the g_io_channel not as watching, like crashing or such..

please see following code :

#include <stdio.h>
#include <gio/gio.h> // g_timeout_add
#include <gtk/gtk.h> // gtk 
#include <netinet/in.h> //sockaddr_in
#include <sys/socket.h> // socket();
#include <arpa/inet.h> // inet_addr();
#include <string.h> // memset();


struct dada
{
    gint id_sock;
    guint id_gio_watch;
};




gboolean incoming(GIOChannel *chan, GIOCondition condition, struct dada *didi )
{
    int byte;

    int insock = g_io_channel_unix_get_fd(chan);

    #define MAXMAX 128
    char buff[128];

    printf("sock : %d\n",insock);

    byte = recv(insock,buff,MAXMAX-1,0);

    if(byte <= 0)
    {
        perror("recv");
        close(didi->id_sock);
        g_source_remove(didi->id_gio_watch);
        return FALSE;
    }
    else
    {
        buff[byte] = '\0';
        printf("coming : %s",buff);
    }

    return TRUE;
}


// gtk area

void hello(GtkWidget *widget, gpointer data)
{
    g_print("Haii world  %s\n", (char *)data);

}


gint delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
{
    g_print("a delete event has been occured properly :D\n");

    return(0);  
}

void destroy(GtkWidget * widget, gpointer data)
{
    gtk_main_quit();  
}
// end of gtk area



int main(int argc, char **argv)
{

    //gtk bussines from here
      GtkWidget *window;
    GtkWidget *button;

     gtk_init(&argc,&argv);
     window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_signal_connect(GTK_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC(delete_event), NULL);
    gtk_signal_connect(GTK_OBJECT(window), "destroy", GTK_SIGNAL_FUNC(destroy), NULL);
    gtk_container_set_border_width(GTK_CONTAINER(window),10);

    button = gtk_button_new_with_label("ohayo");

    gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(hello), (gpointer)"hha" );
    gtk_signal_connect_object(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(window));

    gtk_container_add(GTK_CONTAINER(window),button);

    gtk_widget_show(button);
    gtk_widget_show(window);

    //gtk bussiness done here...


    // network code //
    struct dada didi;
    memset(&didi,0,sizeof(didi));

    struct sockaddr_in my; // set my network device info
    gint rootsock;         // handle the root socket

    //socket
    rootsock = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);

    //binding
    memset(&my,0,sizeof(my));
    my.sin_addr.s_addr = inet_addr("127.0.0.1");
    my.sin_family      = AF_INET;
    my.sin_port        = htons(1111);
    //bind(rootsock,(struct sockaddr*)&my,sizeof(my));

    printf("sock : %d\n",rootsock);
    connect(rootsock,(struct sockaddr*)&my,sizeof(my));

    didi.id_sock = rootsock;
    didi.id_gio_watch = g_io_add_watch(g_io_channel_unix_new(didi.id_sock),G_IO_IN|G_IO_OUT,(GIOFunc)incoming,&didi);

    // network code //

     gtk_main();





    return 0;






}

compiling :

$ gcc -o konek_gioglib konek_gioglib.c `pkg-config glib-2.0 --libs --cflags gtk+-2.0`

my own pc run as server with port 1111 and stream connection ( TCP ) :

$ nc -v -l 1111

running my app :

$ ./konek_gioglib
sock : 6
sock : 6

server got connection and send some word :

$ nc -v -l 1111
Connection from 127.0.0.1 port 1111 [tcp/*] accepted
a
a

and when the server send something, gtk window show but with error like these :

enter image description here

is there anyone dont mind to explain, why these things could happened to mine ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T19:33:06+00:00Added an answer on May 20, 2026 at 7:33 pm

    well last night I brainstormed myself with my own heart, and finally could make these thing work,

    here the proper code

    #include <stdio.h>
    #include <gio/gio.h> // g_timeout_add
    #include <gtk/gtk.h> // gtk
    #include <netinet/in.h> //sockaddr_in
    #include <sys/socket.h> // socket();
    #include <arpa/inet.h> // inet_addr();
    #include <string.h> // memset();
    #include <fcntl.h>
    #include <stdlib.h>
    
    struct dada
    {
        gint id_sock;
        guint id_gio_connect;
        guint id_gio_watch;
    };
    
    
    gboolean readdata(GIOChannel *chan,GIOCondition condition, struct dada *didi)
    {
    
      gchar dada[20] = {0};
      int dadaz =0;
    
    
     if( condition != G_IO_IN )
        return FALSE;
    
    
    
      if(dadaz = recv(g_io_channel_unix_get_fd(chan),dada,19,0)<=0)
      {
          perror("recv");
          close(didi->id_sock);
          g_source_remove(didi->id_gio_connect);
          g_source_remove(didi->id_gio_watch);
          exit(0);
          return FALSE;
      }
    
          printf("data in : %s\n",dada);
    
    
    
    
             return TRUE;
    }
    
    
    gboolean incoming(GIOChannel *chan, GIOCondition condition, struct dada *didi )
    {
    
    
         if( condition & G_IO_ERR || condition & G_IO_HUP )
         return FALSE;
    
    
        didi->id_gio_watch = g_io_add_watch(chan,G_IO_IN | G_IO_ERR | G_IO_HUP,(GIOFunc)readdata,didi);
    
    
        return FALSE;
    }
    
    
    // gtk area
    
    void hello(GtkWidget *widget, gpointer data)
    {
        g_print("Haii world  %s\n", (char *)data);
    
    }
    
    
    gint delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
    {
        g_print("a delete event has been occured properly :D\n");
    
        return(0);
    }
    
    void destroy(GtkWidget * widget, gpointer data)
    {
        gtk_main_quit();
    }
    // end of gtk area
    
    
    
    int main(int argc, char **argv)
    {
    
        //gtk bussines from here
          GtkWidget *window;
        GtkWidget *button;
    
         gtk_init(&argc,&argv);
         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_signal_connect(GTK_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC(delete_event), NULL);
        gtk_signal_connect(GTK_OBJECT(window), "destroy", GTK_SIGNAL_FUNC(destroy), NULL);
        gtk_container_set_border_width(GTK_CONTAINER(window),10);
    
        button = gtk_button_new_with_label("ohayo");
    
        gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(hello), (gpointer)"hha" );
        gtk_signal_connect_object(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(window));
    
        gtk_container_add(GTK_CONTAINER(window),button);
    
        gtk_widget_show(button);
        gtk_widget_show(window);
    
        //gtk bussiness done here...
    
    
        // network code //
        struct dada didi;
        memset(&didi,0,sizeof(didi));
    
        struct sockaddr_in  your; // set my network device info
        gint rootsock;         // handle the root socket
    
        //socket
        rootsock = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
    
    
    
        memset(&your,0,sizeof(your));
    
    
        printf("sock : %d\n",rootsock);
    
        your.sin_family = AF_INET;
        your.sin_addr.s_addr = inet_addr("127.0.0.1");
        your.sin_port   =   htons(1111);
    
        connect(rootsock,(struct sockaddr*)&your,sizeof(your));
    
        didi.id_sock = rootsock;
        didi.id_gio_connect = g_io_add_watch(g_io_channel_unix_new(didi.id_sock),G_IO_IN | G_IO_OUT | G_IO_ERR | G_IO_HUP,(GIOFunc)incoming,&didi);
    
        // network code //
    
         gtk_main();
    
    
    
    
    
        return 0;
    
    
    
    
    
    
    }
    

    and the only different had made is the “worked” code , need :

    - gio for connecting, and gio for watching
    

    instead of be “non-worked” code ( only gio for connecting ), but again i just wondering “why”, why on connect() need two gio (recursively) in order make these “gio things” work,

    these is really odd, if I see back then on g_io_channel + socket = server , still just get one client ? in C language

    which on accept() just need only one gio and only for watching.

    if someone could explain these, how great it’ll be 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, I am going for the total shotgun question here. I tried to create
My goal is create an app client server, written in C++. When the server
I'm an actionscript dude - I'm working on a papervision game. I have an
In AS3, if I have a class such: public class dude { //default value
I'm looking to capture just the number after vspace . How would you do
Visual Studio 2008 Database Edition (Data Dude) has the ability to perform schema comparisons
There is this random dudette or dude on facebook that added my as a
Table structure sl_ no A B TOTAL 1 DUDE SAM 5 4 COOL DUDE
TABLE tab sl_no name marks status 1 dude 33 y 2 dudz 38 y
Given the string "the dude is a cool dude", I'd like to find the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.