Jump to content

Simple network example


Josh
 Share

Recommended Posts

This is a minimal example showing how a program can communicate. From here, you can imagine how chatting could work, and then how keyboard input could be used to control a player over a network. If the network commands are not found, just run the updater.

 

1. Drag server.lua onto engine.exe.

2. Draw client.lua onto engine.exe.

 

I will continue with this, but I hope the community will jump in, too, so we can make a basic program. I will admit I am not an expert at networking. But there's not really that much going on in a networked game, because the server generally controls everything, and the clients just provide keyboard input and get back positions and other information.

simplenetwork.zip

  • Upvote 2

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Mack look under "Attached File(s)" in the lead post ... sheeesh :D n00b... lol

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

This is a cool tutorial. I'm going to play around with making a network object that you can drag into your scene and then specify if it's client/server and have some other settings. Thanks for the start!

 

But there's not really that much going on in a networked game, because the server generally controls everything, and the clients just provide keyboard input and get back positions and other information.

 

Not really. The client generally will do some of the same things the server will do to give instant feedback to the player. If I press the move forward key and it has to wait for a round trip before I can move forward it's very noticeable and creates input lag. So really the client has to both move forward locally and then send off it's position to the server.

 

My new plan of attack is to have the clients do the physics for their own character only and send it's position & rotation to the server 8 times (or so) a second. The server will then validate that the position & rotation isn't so far fetched that it's obvious the client is cheating. So on my client my character will be the only character that has a controller assigned to it. All the other players on my client will just be getting position & rotation from the server, but since the server would be getting position & rotation from the actual clients who all have their controller assigned to their character it'll all look OK on all client machines.

 

With LE, the main issue with having the server do all physics is that you still need to simulate your characters physics locally to avoid input lag. If your client doesn't have a controller and just sets the position & rotation of your character model, then your client doesn't have physics locally. So that means it takes a round trip to get the position of your character on your screen. Let's say you walk off a cliff. You will get a Wiley Coyote effect because locally you don't have physics which means when you walk off the cliff your toon would just be standing in mid-air. 1/4 of a second later, or if you hit a lag spike it could be longer, then your toon starts to fall.

 

This little lag is perfectly fine for the other players on your client because it'll all look smooth anyway. You are already 1/4 of a second behind them at all times anyway, but for your own character the feedback of things you do needs to be instant or the game will feel very choppy and hard to play.

 

This is all what I'm about to test out.

Link to comment
Share on other sites

I think this method of having the client do physics locally and send it's position & rotation back to the server to send to everyone would work really well. It offloads the physics of just that clients character to their machine freeing up the server because it doesn't need to do any physics. The client machine isn't really doing a ton of work because it's only doing physics for it's own character and not all the others. The client also gets instant feedback from moving around which is ideal. The only issue with this is when the client wants to do something that affects another client through physics. In this case it would require the round trip of going to the server and telling the server to tell this client to do this physics action on itself, and then back to the server with the position and back to the client who started the action. Might be a slight delay there. Also a hacker could stop the physics message from acting on it's client, but that's what server checks are for. :)

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...