Very basic approach - multiplayer game lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- process_1 · 2020-07-29 03:22 I have actually never done that before. What I'm trying is to make a  multi-user game (2 players at least). Each user's app should be aware of other connected users action which should be managed by the internet server. I cannot host it from my machine, thus it have to be able to be hosted from some public and free server to coordinate connections and actions, assuming the server itself do not support anything else except JS, PHP and MySQL (i.e. no CGI support or anything else). Basically, it should behaves as any multiplayer game today. In this case the server app should be written in pure JS and client app is normal Lazarus GUI app able to exchange data with server and other players. Anyone is aware of some simple examples how to create such server and client app? ---------------------------------------------------------------------- Handoko · 2020-07-29 03:34 On the link below, goto section Networking > Game Client and Server: https://wiki.freepascal.org/Portal:HowTo_Demos Although that is still far for a game client/server, but rvk's code really shows the basic for doing it. ---------------------------------------------------------------------- process_1 · 2020-07-29 03:56 Thank you Handoko, Unfortunately, AFAICS, the server is an executable? As I have wrote, the server app need to be on a public server, which do not allow any executables. ---------------------------------------------------------------------- Cyrax · 2020-07-29 07:01 Quote from: process_1 on July 29, 2020, 05:56:09 amThank you Handoko, Unfortunately, AFAICS, the server is an executable? As I have wrote, the server app need to be on a public server, which do not allow any executables. Luckily, FPC trunk have pas2js transpiler : https://wiki.freepascal.org/pas2js You can create a server application by using it. ---------------------------------------------------------------------- PascalDragon · 2020-07-29 07:24 Quote from: process_1 on July 29, 2020, 05:56:09 amUnfortunately, AFAICS, the server is an executable? As I have wrote, the server app need to be on a public server, which do not allow any executables. You could try whether you can execute some application if invoked by a PHP script (e.g. using exec()) that can then detach and continue running in the background. But if not and the server does not allow at least CGI you're out of luck for using FPC. (That's why I made sure that my hosting provider allows at least CGI) ---------------------------------------------------------------------- process_1 · 2020-07-29 08:24 Using executables is explicitly forbidden by their antivirus and anti- malware policy. Other provides I looked also have such clause. Then, it is just bad luck. ---------------------------------------------------------------------- d.ioannidis · 2020-07-29 09:21 Hi, Quote from: process_1 on July 29, 2020, 05:56:09 amThank you Handoko, Unfortunately, AFAICS, the server is an executable? As I have wrote, the server app need to be on a public server, which do not allow any executables. maybe you should consider a cheap Cloud VM with your choice of OS . For example, with a quick google search , I found this https://www.kamatera.com/express/compute/products.php : 1 CPU 2667 MHz 1 GB RAM 20 GB SSD 1 IP 5000 GB Traffic / month for $4 / month. This is what I've done some time ago, ( not with Kamatera, I use other provider ) and I'm glad I did it. regards, ---------------------------------------------------------------------- MarkMLl · 2020-07-29 12:13 Quote from: process_1 on July 29, 2020, 05:22:10 amI have actually never done that before. (...) I cannot host it from my machine, thus it have to be able to be hosted from some public and free server to coordinate connections and actions, assuming the server itself do not support anything else except JS, PHP and MySQL (i.e. no CGI support or anything else). Strictly, all you need on the public machine is some sort of reflector that allows other connected systems to share their current IP addresses. There's obviously a risk that that sort of thing could trigger various anti-DDOS protection etc. but I've got a vague recollection that I've seen things like Github being used for it. MarkMLl ---------------------------------------------------------------------- totya · 2020-07-29 13:47 Quote from: Dimitrios Chr. Ioannidis on July 29, 2020, 11:21:09 amfor $4 / month. QuoteType A – Availability – Server CPUs are assigned to a non- dedicated physical CPU thread with no resources guaranteed. ---------------------------------------------------------------------- BeniBela · 2020-07-29 15:58 By the way, I made a game with Delphi to learn network programming.  It is not open-source though. One player is the server, the others are the clients. Like at a LAN party. No internet required and no central server ---------------------------------------------------------------------- marcov · 2020-07-29 16:07 I'm already surprised that it allows serverside javascript. Seems like a plus feature ---------------------------------------------------------------------- process_1 · 2020-07-29 16:13 BeniBela, Long long time ago I have made a chat program in Delphi using Francois Piere ICS between two people. It required only to exchange IPs, then one to be server side and another client. That was fairly simple, but with internet server hosting, possibilities are much bigger, primary there is no reson to use your own local server machine to host the server app. I would probably test pas2js and see is it suitable and is itl work at all, instead to write entired server app in JS manually. ---------------------------------------------------------------------- zamronypj · 2020-07-30 04:04 Quote from: process_1 on July 29, 2020, 05:22:10 amI cannot host it from my machine, thus it have to be able to be hosted from some public and free server to coordinate connections and actions, assuming the server itself do not support anything else except JS, PHP and MySQL (i.e. no CGI support or anything else). Depending on type of game you want to develop, TCP may not be suitable. For example, real-time game will mostly use UDP instead of TCP. On shared host server, most likely, administrator will only allows certain port to be open, so running application listen on arbitrary port mostly will not work. Your privileges are also mostly very limited (considered lucky if you, even, have SSH access). Running JS/PHP UDP server code which listen to port requires at least SSH access. I suggest you to at least use VPS so that you can install and running application as root if you want to setup such server. ---------------------------------------------------------------------- process_1 · 2020-07-30 10:17 Quote from: zamronypj on July 30, 2020, 06:04:26 amDepending on type of game you want to develop, TCP may not be suitable. It is turn-based tactic/strategy 2D game with quite low data packets to send, even 300bps modem transfer would be sufficient for 2 players only. Any latency under 1s is tolerant. For more than 2 people let assume just to multiply needed transfter, thus for 1MB/s banwidth that is about 7000 people online max., which is more than I belive ever will be reached. Thus required resources are quite low for nowadays standards. ---------------------------------------------------------------------- MarkMLl · 2020-07-30 10:23 If you want to send preformatted packets around, and can cope with handling retries yourself, consider UDP. If you want to send strings/streams around, use TCP. There's a compromise protocol called SCTP (block-oriented but handles retries automatically) but it won't go through network connections which are heavily NATted (e.g. IP4 to mobile devices). MarkMLl ---------------------------------------------------------------------- zamronypj · 2020-07-30 15:26 Quote from: process_1 on July 30, 2020, 12:17:07 pm It is turn-based tactic/strategy 2D game with quite low data packets to send, even 300bps modem transfer would be sufficient for 2 players only. Any latency under 1s is tolerant. For more than 2 people let assume just to multiply needed transfter, thus for 1MB/s banwidth that is about 7000 people online max., which is more than I belive ever will be reached. Thus required resources are quite low for nowadays standards. For me, it looks like you can use websocket. It offers bi-directional communication and it uses well-known http port for initial handshake. Quote from: MarkMLl on July 30, 2020, 12:23:16 pmIf you want to send preformatted packets around, and can cope with handling retries yourself, consider UDP. In real-time game, losing few packets of players positions data will not be a big deal as it will be overwritten with new data anyway. So real time game with UDP does not bother to try to resend lost packets.