Yue Posted March 1, 2023 Share Posted March 1, 2023 Hello, someone with experience please clarify how client server programming works, I'm looking at how it works, programming from the server, and programming from the client. Quote Link to comment Share on other sites More sharing options...
IceBurger Posted March 1, 2023 Share Posted March 1, 2023 I assume this is for implementing multiplayer in a game (which I am fairly familiar with). In the client-server model, the clients all connect to a central server which manages their data. A client will send inputs and suggestions to the server, which, after verification, will then send new positional and other data to all the clients. You can think of the server as being a verificational proxy for the clients. What inputs are sent to the server and what amount of verification is done is up to the game developer. Every implementation will have its own pros and cons. Here is an example diagram of a potential client-server relationship: Hopefully I have interpreted your question correctly, if so please ask for more clarity/information. If you are asking for how to implement this into Leadwerks/Ultra and not just general concepts, sorry I haven't tried doing that yet and therefore would be zero help. 1 1 Quote i now hate love C++ Beeeeeeeeeeeeeep~~This is a test of the emergency signature system~~Beeeeeeeeeeeeeep RX 6800XT | i5-13600KF | 32GB DDR5 | 1440p is perfect Link to comment Share on other sites More sharing options...
Yue Posted March 1, 2023 Author Share Posted March 1, 2023 17 hours ago, IceBurger said: Supongo que esto es para implementar el modo multijugador en un juego (con el que estoy bastante familiarizado). En el modelo cliente-servidor, todos los clientes se conectan a un servidor central que administra sus datos. Un cliente enviará entradas y sugerencias al servidor que, después de la verificación, enviará nuevos datos posicionales y de otro tipo a todos los clientes. Puede pensar en el servidor como un proxy de verificación para los clientes. Qué entradas se envían al servidor y qué cantidad de verificación se realiza depende del desarrollador del juego. Cada implementación tendrá sus propios pros y contras. Aquí hay un diagrama de ejemplo de una posible relación cliente-servidor: Espero haber interpretado su pregunta correctamente, si es así, solicite más claridad/información. Si está preguntando cómo implementar esto en Leadwerks/Ultra y no solo en conceptos generales, lo siento, no he intentado hacerlo todavía y, por lo tanto, no sería de ayuda. A concrete question would be, if a car is created from a server, it is seen by all clients, if it is created from a client, none of the other clients will see it? It is that I have API of writing code from the client and from the server. Something confusing for me. Quote Link to comment Share on other sites More sharing options...
Solution IceBurger Posted March 1, 2023 Solution Share Posted March 1, 2023 7 minutes ago, Yue said: A concrete question would be, if a car is created from a server, it is seen by all clients, if it is created from a client, none of the other clients will see it? It is that I have API of writing code from the client and from the server. Something confusing for me. You would have to decide whether you want the server or clients to manage the creation of cars. Here are some options for this scenario: 1) [This is the most authoritative way] The server manages the creation and translation of cars. The server keeps track of player positions and spawns cars near them and removes cars that are far away. The server then sends the position, type, rotation, etc. data to the clients. 2) [This is the least authoritative way] The clients manage the creation and translation of cars. A client creates cars near itself and then tells the server to inform the other clients that a car has been created. When a car is far from the client, the client tells the server to tell the other clients that a car has been removed. Extra logic could be added so that clients too far away from the new car don't receive the creation message. With client-server networking you must choose whether you want certain logic to be done on the client-side or the server-side. Typically games choose a middle-ground where the client makes predictions about what the server is going to do, but the server has the final say for whether other clients see that happen. Here is some pseudo-code for one of the simplest client-server networking implementations. This code deals with players, but the same concept would apply to cars. Again, this is just one way of many. This implementation below has several flaws, but hopefully it makes sense. // CLIENT let players = []; let loop = new GameLoop(60); let conn = new Connection(127.0.0.1:8080, "tcp"); conn.onMessage(function(message) { // go through all sent players from server for (player in message.players) { // create new players if (!players[player.id]) players.add(new Player()); // set the positions from the server players[player.id].position = player.position; } }); loop.onTick(function() { // gather input let input = { moveLeft: Engine.keyDown("a"), moveForward: Engine.keyDown("w"), ... }; // send input conn.send(input); }); // SERVER let players = []; let loop = new GameLoop(60); let server = new ConnectionReceiver(8080, "tcp"); server.onConnect(function(conn) { // recognize new player joined players.add(new ServerPlayer(conn)); }); server.onInputMessage(function(input, id) { players[id].useInput(input); // makes changes to stored server data }); loop.onTick(function() { // send players to clients for (player in players) { player.conn.send({ players }); } }); Quote i now hate love C++ Beeeeeeeeeeeeeep~~This is a test of the emergency signature system~~Beeeeeeeeeeeeeep RX 6800XT | i5-13600KF | 32GB DDR5 | 1440p is perfect Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.