Does anyone know an example C program for Windows to set up a TCP/IP server?
I would like to create a tool for allowing peer-to-peer play between GUIs. The logical way to do it would be to create a pseudo-engine that runs as engine under the GUI, which starts a thread to listen on a certain port, and alternatively can connect to that port on another machine when the user commands it to do so (through a URL string and a 'Connect' button in the Engine Settings dialog of the GUI). Once a bidirectional connection is established between the pseudo-engines on the different machines, the pseudo-engines acknowledge their readiness by sending am until-then-delayed 'pong' command to the GUI, commencing the game.
Operating the 'Connect' button would automatically make the pseudo-engine seeking the connection abort any ongoing game on its own GUI by resigning it. Once the connection is established, the pseudo-engines would cause popups on their respective GUIs urging the user to start a game in a compatible color (if that was not already started); the first to start a game would be the one to decide what these colors are, but the other can refuse it by making a counter-proposal, through starting the other color. (This will cause an immediate resign towards the remote opponent, so he can now pick the opposite color from what he first did; an automated opponent running in match mode would do this automatically.)
I do have example code from WinBoard how to seek a TCP connection (to an ICS), but I have no idea how I could 'listen' to a port for incoming connection requests (in Windows).
Q: Windows API for setting up a TCP server
Moderators: hgm, Rebel, chrisw
-
- Posts: 27837
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
-
- Posts: 670
- Joined: Mon Dec 03, 2007 3:01 pm
- Location: Barcelona, Spain
-
- Posts: 27837
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: Q: Windows API for setting up a TCP server
Many thanks, this seems exactly what I need!
-
- Posts: 4368
- Joined: Fri Mar 10, 2006 5:23 am
- Location: http://www.arasanchess.org
Re: Q: Windows API for setting up a TCP server
You might consider doing this in Java - it is cross-platform and the Java networking APIs are not too difficult.
See http://docs.oracle.com/javase/tutorial/ ... erver.html.
--Jon
See http://docs.oracle.com/javase/tutorial/ ... erver.html.
--Jon