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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

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

TCP/IP Network Protocol Cheat Sheet

TCP/IP is a set of network protocols which is best known for connecting the machines that make up the Internet. The truth is that TCP/IP is one of the oldest network protocols and its survival is mainly based on its simplicity and universality.

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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month7 days, 20 hours left to enroll

765 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