I am trying to make a chess like 2-player game that has game logic written in C++ and front end in JavaScript. How do I exchange information between the two? I am not familiar with network programming, so resources regarding that would be helpful as well.

  • \$\begingroup\$ Did you choose a web server already, or do you want to roll your own? For the latter, see Beej's Guide to Network Programming and A Simple Webserver in C++ for Windows - If you are looking for a tool for web development using C++ see wt or TreeFrog - There must be others - Aside from that, consider to use an embeded web server for a managed/virtual-machine language and use whatever solution for C++ interop it has. \$\endgroup\$ – Theraot May 13 '17 at 5:55
  • \$\begingroup\$ I got the idea of doing this from LiChess. Can you tell me how this does front end and server interaction? \$\endgroup\$ – Shaurya Gupta May 13 '17 at 5:59
  • 2
    \$\begingroup\$ They use scala to handle the web requests using Play Framework. In their case the server is handling routing information between the players. At some point the client open a websocket connection to the server, and the server is routing these connections to allow the playes to communicate. That is not the only way to do it. Before websockets it was possible to mimic this behaviour by keeping a HTTP connection open and having partial responses. A more modern alternative is WebRTC. \$\endgroup\$ – Theraot May 13 '17 at 6:13
  • 1
    \$\begingroup\$ This stackoverflow post seems to be discussing a more specialised version of this problem, focusing on ajax (Asynchronous Json And Xml), which jquery has support for. \$\endgroup\$ – Pharap May 13 '17 at 14:46
  • \$\begingroup\$ Do also note that LiChess' solution is highly sophisticated. If you're just starting out, perhaps look into something simpler like a REST framework. If you're not married to the idea of C++, you can get something like this running with a Python backend in under a day from scratch. \$\endgroup\$ – Adam Barnes Jan 23 '18 at 14:33

Just use WebSockets directly.

In C++ you can use µWebSockets to create a server. In JavaScript you can use the WebSocket object to connect to the server and send messages.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.