GUI Socket Programming

Posted on 2003-03-14
Medium Priority
Last Modified: 2010-04-21
I know BSD Sockets. I know a little bit of GTK+. But I am not able to understand how to write GUI applications to combine them both. Is there any other library that I would require to use ? Or any other way that you recommend ?

Thank You,
Question by:pratik20

Expert Comment

ID: 8146704
no u dont need additional library to be able to do that .. may be pthread library to make it multithreaded..\but i guess GTK must already be using some amount of multithreading...
tell us the job / problem at ur hand

Expert Comment

ID: 8152260
Sockets as you know them work in an X-Windows environment. I imagine you probably need to restructure your logic to work in an event-driven model.


Accepted Solution

int_main earned 80 total points
ID: 8153976
Hi pratik20,

Two entirely different worlds here. If you want a good (but complicated) example take a look a the Gnutella source code. The "summarized" answer is that you work with two entirely separate subsystems: the network stuff and the gui stuff. The communication between each subsytems occurs via functions that YOU write for the purposes of the program. Within your functions will be the standard calls to Gtk or the socket library.

Put another way, there are no socket functions (that I know of, though I'm not a Gtk guy) in the gui library and no gui functions in the socket library. Therefore the solution is to have the gui call the socket-related functions as applicable. Likewise certain events, such as an established connection, will trigger or call gui-related functions. Note, however, that such intercommunication is entirely by functions that YOU write; there are no standard intercommunications.

At a very high level this would work as follows:

1) A gui-related event such as a user clicking a "close connection" button would do the following:

- set a flag within YOUR custom connection structure; something like "killcon=1;"

2) Now it's the socket subsystem's turn:

- Using the standard socket function select() you would (eventually) grab the connection structure noted above and check the "killcon" variable.

- Because killcon is 1 you would call YOUR custom routine to perform shutdown on the connection. In this custom routine you would do things like flushing the buffer and ultimately, call close() to kill the connection, send an update to the GUI to alert the user, etc.

Note that in the above description that both systems, that is the gui and the socket, work in a non-blocking manner. This simply means that they don't hold up program execution if there is nothing to do. They just pass control back and forth to each other until something happens. Google around for things like "socket" "select tutorial" to get an idea. I am sure there are some Gtk tutorials out there as well.

I hope this helps get you started. Let me know...


Expert Comment

ID: 8160932
You may want to look at GIOSource in the glib library. It has functions to handle notification of sockets tied in with the GTK+ main loop.

Author Comment

ID: 8164952
Thx for the answer.

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question