problems with gtk_entry_get_text



I am writting a client for my server to finish the server development.

The client I have so far is displaying to a Text Widget and taking user
input from a Text Entry widget. Data entered by the user is changed to be
readable by the server. The server wants 'CHAT TALK: <message>' so if the
user types 'asdf' the server is sent 'CHAT TALK: <username>,asdf'

void hit_enter(GtkWidget *widget, gpointer *data) {
        gchar *string;
        struct gui_info_hold *ptr;

        ptr = (struct gui_info_hold*)data;
        string = gtk_entry_get_text(GTK_ENTRY(widget));
        g_print("User typed: %s\n", string);
        sendPacket(ptr->host_info.sock, string);
        gtk_entry_set_text(GTK_ENTRY(widget), "");
}

void make_dataentry(struct gui_info_hold *gui_info) {
        GtkWidget *data_entry;

        data_entry = gtk_entry_new_with_max_length(512);
        gtk_signal_connect(GTK_OBJECT(data_entry), "activate",
			GTK_SIGNAL_FUNC(hit_enter), gui_info);
        gtk_widget_show(data_entry);
        gui_info->data_entry = data_entry;
}

Indicated below 'before[packet]' is what is recieved from the server so
what is being sent and recieved from the server is accurate the problem is
that more is being sent than indicated by the Text Entry Widget.

I typed: 'hello','hello','hello','heh','um','grin'.

lg:~/src/chat/client$ ./rrclient
host=127.0.0.1; port=2345; nick=Leland
before[packet]CHAT JOIN: Leland
User typed: hello
before[packet]CHAT TALK: Leland,hello
User typed: helloTALK: hello
before[packet]CHAT TALK: Leland,helloTALK: hello
User typed: helloTALK: helloTALK: hello
before[packet]CHAT TALK: Leland,helloTALK: helloTALK: hello
User typed: heh
before[packet]CHAT TALK: Leland,heh
User typed: um
before[packet]CHAT TALK: Leland,um
User typed: grin TALK: um
before[packet]CHAT TALK: Leland,grin TALK: um


While I am asking, there is a reason for that 'before', if I remove the
comment here:

        g_print("before[packet]%s\n", newtext);
        gtk_text_insert(GTK_TEXT(ptr->chat_display_text), NULL, NULL,
			NULL, newtext, strlen(newtext));
//      g_print(" after[packet]%s\n", newtext);

garbage is displayed as if gtk_text_insert corrupts `newtext'?


Travis Loyd
[email: lelandg@usa.net							]
[  pgp: send email with subject: sendmepgp				]




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]