Hi,
I've started looking at making a (simple) chess GUI.
Before doing that, I'd like to understand programming techniques for communication between programs - sending and receiving input.
I've been searching for an introduction to this, but without much success.
Does anyone have any pointers?
Thanks in advance!
Richard
c++ Communication between programs
Moderator: Ras
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: c++ Communication between programs
Regarding GUI-engine communication, the basic principle of the WinBoard GUI, for instance, is to create a pair of pipes - one for sending and one for reading - for each of the locally playing engines. WinBoard then creates the engine processes as child processes of itself and assigns the appropriate ends of the pipes to them. That's all. Now the engines can use normal standard input/output to read from/write to the GUI, and the GUI uses the file descriptors assigned to certain pipe ends.Richard Allbert wrote:Hi,
I've started looking at making a (simple) chess GUI.
Before doing that, I'd like to understand programming techniques for communication between programs - sending and receiving input.
I've been searching for an introduction to this, but without much success.
Does anyone have any pointers?
Thanks in advance!
Richard
As described in the WinBoard engine interface specs, either flushing output directly after writing or even switching off output buffering is essential to ensure that the other side can receive the message immediately, provided input buffering is switched off, too, at the other side.
Other GUIs will most certainly do similar things, same for WinBoard protocol as for UCI. Also you are not completely free in designing the way your GUI communicates to engines if you want to develop a GUI that is compatible to one of these two standard protocols.
For playing against an opponent on ICS, sockets are used instead of pipes.
There is probably some material about this in CCC.
In case you are not familiar with pipes you can search the net for "UNIX pipes" (e.g. wikipedia.de). Note however that the concept is not restricted to UNIX. Consider also looking at the WinBoard source available through the WinBoard forum.
Sven
-
- Posts: 794
- Joined: Wed Jul 19, 2006 9:58 am
Re: c++ Communication between programs
Hi Sven, thanks for the reply.
I have looked (briefly) at the winboard source - it's big, so I wanted some pointers before doing that to be able to understand what I was looking at.
There a lots of google hits for UNIX pipes...
Thanks for the tip.
Richard
I have looked (briefly) at the winboard source - it's big, so I wanted some pointers before doing that to be able to understand what I was looking at.
There a lots of google hits for UNIX pipes...


Thanks for the tip.
Richard
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: c++ Communication between programs
I use the very first ones in such cases. Should be wikipedia, I guess.Richard Allbert wrote:There a lots of google hits for UNIX pipes...![]()
![]()
Sven
EDIT: As to the WB sources, you could search for "popen" there.
EDIT2: Or better for "StartChildProcess" (winboard.c, xboard.c).
-
- Posts: 2684
- Joined: Sat Jun 14, 2008 9:17 pm
Re: c++ Communication between programs
I'd suggest to carefully chose the GUI library:Richard Allbert wrote: I've started looking at making a (simple) chess GUI.
- Multi OS ? Portable ?
- Programming languages supported ?
- Software license ?
- Well documented ?
And so on...
This is the single most impostant part before strating with a GUI.
IMHO Qt is absolutely the best under all the above points and it is also very elegant designed. But it takes a bit to get used to.
P.S: under Qt, QProcess class will do all the comuncation stuff for you, in case you need some examples take a look at cutechess that is built upon Qt and its sources are very high quality, professional quality code.
-
- Posts: 750
- Joined: Mon Mar 27, 2006 7:45 pm
- Location: Finland
Re: c++ Communication between programs
Thanks for the compliment. I would especially recommend taking a look at our EngineProcess class, which is a replacement I wrote for QProcess in Windows. Here's a relevant extract from engineprocess_win.h:mcostalba wrote:P.S: under Qt, QProcess class will do all the comuncation stuff for you, in case you need some examples take a look at cutechess that is built upon Qt and its sources are very high quality, professional quality code.
Basically QProcess on Windows was optimized for massive amounts of data arriving at the same time, but the latency is just too much for chess.Due to polling, QProcess' response times on Windows are too slow for
chess engines. EngineProcess is a different implementation which reads
new data immediately (no polling) when it's available. The interface is
the same as QProcess' with some unneeded features left out.
On non-Windows platforms EngineProcess is just a typedef to QProcess.
-
- Posts: 794
- Joined: Wed Jul 19, 2006 9:58 am
Re: c++ Communication between programs
Ok, thanks, I'll have a look.
I'm intending to do something very basic, though. Just for fun.
Richard
I'm intending to do something very basic, though. Just for fun.
Richard
-
- Posts: 778
- Joined: Sat Jul 01, 2006 7:11 am
Re: c++ Communication between programs
Has anyone looked into using sockets? If it worked, it would make communicating locally or remotely simple.Richard Allbert wrote:Hi,
I've started looking at making a (simple) chess GUI.
Before doing that, I'd like to understand programming techniques for communication between programs - sending and receiving input.
I've been searching for an introduction to this, but without much success.
Does anyone have any pointers?
Thanks in advance!
Richard
-
- Posts: 61
- Joined: Thu Oct 22, 2009 1:50 am
- Location: Barcelona Spain
Re: c++ Communication between programs
hi,
To communicate processes in c you can use 3 things
a) PIPES
b) name pipes
c) sockets
in a chess uci protocol or winboard it's used the first.
Take a look at whatsoever uci parser to understand the idea.
Best regards
To communicate processes in c you can use 3 things
a) PIPES
b) name pipes
c) sockets
in a chess uci protocol or winboard it's used the first.
Take a look at whatsoever uci parser to understand the idea.
Best regards
-
- Posts: 20943
- Joined: Mon Feb 27, 2006 7:30 pm
- Location: Birmingham, AL
Re: c++ Communication between programs
The problem is that you want to use the dup2() facility to make the chess engine read from whatever you want it to read from, while it thinks it is reading from stdin. However, the engine has to cooperate in this because of the various buffering issues if you use traditional I/O such as scanf, gets, etc...jwes wrote:Has anyone looked into using sockets? If it worked, it would make communicating locally or remotely simple.Richard Allbert wrote:Hi,
I've started looking at making a (simple) chess GUI.
Before doing that, I'd like to understand programming techniques for communication between programs - sending and receiving input.
I've been searching for an introduction to this, but without much success.
Does anyone have any pointers?
Thanks in advance!
Richard