Hi there,
Well I figured it out... sorda, like I said I just started working with
this but in reading the posts it dawned on me, The callback! Yes that is
it. I can pass pointers into the callback... what I did was pass the
address of sockfd to the connect button, the connect function just
puts int in the memory location. well, you guys know.Then when I click
the send button I pass it the address of sockfd as well. That seems
to work. of course I will need to actually pass a struct to
send so that I can give it information as to where to
get the text to send (rigth not it is just a hard coded test message) and
whatever else it needs but I am on the way.
Again, I just started with this and there is a little more of a learning
curver than with java but it is alot of fun!
Thanks
Ken
here is some code.
/********** the connect function **********************/
static void connect_to_server(GtkWidget *widget, int *sockfd)
{
struct sockaddr_in dest_addr; /* will hold the destination addr
*/
if ((*sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
perror("socket"); exit(1); }
dest_addr.sin_family = AF_INET; /* host byte order */
dest_addr.sin_port = htons(DEST_PORT); /* short, network byte
order */
dest_addr.sin_addr.s_addr = inet_addr(DEST_IP);
bzero(&(dest_addr.sin_zero), 8); /* zero the rest of the
struct */
if (connect(*sockfd, (struct sockaddr *)&dest_addr, sizeof(struct
sockaddr)) == -1)
{ perror("connect"); exit(1); }
}
/********** this is how I call it from main *********************/
g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK
(connect_to_server), &sockfd);
On Thu, 26 Jan 2006, Freddie Unpenstein wrote:
Date: Thu, 26 Jan 2006 06:02:55 -0500 (EST)
From: Freddie Unpenstein <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED], gtk-app-devel-list@gnome.org
Subject: RE: programming practices with regard to gtk and networking
What I need to do is somehow create the connection when the button
is clicked and then pass the sockfd to the calling part of the
programming (main) so I can then use that in the calls to send().
What I really need is someone to point me in the right direction.
How many connections will you be making? How long will these connections
persist? And what new signal connections will you be making after this
connection has been made?
Sounds to me like you'd be better off creating an object that handles the
connection. The object would offer methods to create a connection, send and
receive messages and what-not, and finally close the connection.
You could then create a new (un-connected) "connection" object, and pass a reference to
that in the user_data of the button. The button would then just have to trigger the
"connect" method of the object.
If you want to avoid creating a whole GObject for it, you can just put together
a struct with all the relevant bits and pieces, and call all your functions
with a naming structure similar to what GTK uses. (Which is basically all an
object is anyhow, until you start adding OOP features like inheritance,
property introspection, etc.)
Fredderic
_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list