Winsock2 based TCP client with GUI (how to combine TCP console application with GUI)

130 Views Asked by At

I have a console application running as a TCP client using Winsock2. This application connects to a server which regularly provides measuring data, and needs to get some configuration from my client. It's all programmed in C and I use the mingw64 compiler.

Sending and receiving is non-blocking, ie I do not need to wait for any receive data to continue code execution. This allows me to independently send and receive data, without being blocked when no data is received.

As a console application does not really look nice for visualization of the received data, and does not provide push buttons to send configuration sets, I'm trying to add a GUI.

Therefore, I followed http://winprog.org/tutorial/ to get an idea on how to program a GUI.

Now, as a next step, I tried to include my TCP communication into a Windows GUI application, but that's the point where I fail.

At the point where the Windows application has set up the GUI window, I added my code for establishing the TCP connection.

After that, the original GUI program turns within the message loop forever. Therefore I've put my TCP receiving code into this loop too, with the idea that it is permanently executed. But this assumption is obviously wrong. I do not get any data received from the established connection. The message loop seems to be sleeping as long as there is no action on the GUI, ie as soon as I move the mouse pointer, the whole bunch of data comes in.

How/where can I place my C code that should be permanently executed, to run along with the GUI?

Unfortunately, I was not able so far to find a suitable example, simple enough for me to understand.

0

There are 0 best solutions below