Dependancies on different computers

The Partridge Family were neither partridges nor a family. Discuss.
User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Dependancies on different computers

Post by LuX » June 30th, 2012, 7:09 pm

Here's a better version of a client - server - client communication.
I added both the server and client, you can open as many clients as you want.

You should see on the server screen all IPs connected. Then, you can write something on the client screen, press enter and it will send the string to the server and then echo it back to the client (remember to launch clients using crtl F5 or press the empty triangle multiple times for many clients).

Edit: They way I would do it, is have the server do all the calculations and hold coordinates etc.
So what happens is first the client tells what he wants to do, eg. move up. This info will be sent to the client and it will calculate the new coordinates and send it back so all the client does next, is draw the screen based on the info sent. Obviously I wont be sending an array of pixels or something, but rather tell for example enemy position and radius, then the client can draw the circle based on this info.

PS here's the site I stole this from. I had to do some modifications to make it work on 2010 c++, tho. Link
Attachments
Server+Client.rar
(302.96 KiB) Downloaded 137 times
ʕ •ᴥ•ʔ

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Dependancies on different computers

Post by Asimov » June 30th, 2012, 9:46 pm

Hi Lux,

I just imagined your game, but with a screen bigger than the current window. Say with 20 network players all with ships struggling to survive, and the possibility of upgrading ships and teaming up to fight the evil transparent balls of doooooooooooom, with the sounds of Jerry Lee Lewis singing great balls of fire as the soundtrack, or the chef from southpark singing Chocolate salty balls LOL.

Asimov

EDIT: Just had a look at the server code. Seems like a lot of code that almost does the same thing. Also in the server code I can't see anywhere where the ip is put. So it must be picking it's own ip somehow, which is not so good if you use a router and need an outside ip. Will study it slowly. Also I notice he is using some bad programming practices using 'goto' far too much LOL. I didn't even know there was a goto command in C++, that surprised me. Haven't used it since the old BASIC days heh heh.
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Dependancies on different computers

Post by LuX » July 1st, 2012, 10:56 am

The server doesn't need an IP, it uses a port instead.

To be honest I don't know why goto would be bad statement to use, I've used it a lot in my shooter game. I can see it might potentially fuck up the code, but if used carefully it's a pretty good way to use a code multiple times. But in c++ I rarely find a situation where I need to use it. In my shooter game the only time I really needed it was when using a shotgun to fire multiple bullets in one shot, but I guess it could be rewritten to a more simple way.

But yeah, in VB goto was a must for any coder : -D Mostly for code skipping while still staying in the same function.
ʕ •ᴥ•ʔ

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Dependancies on different computers

Post by Asimov » July 1st, 2012, 11:31 am

Hi Lux,

Even though you can't see it in the code a server has to use an ip and a port, or it won't work. If you look carefully at the code it auto picks up the ip. Whereas the code I posted lets you input it yourself.
However I am still having problems testing my server outside my computer. The problem is that if you use telnet to test it only works locally. Been searching for an online telnet to test outside my computer but not found one.

Gotos and global variables are bad practice in object orientated code. It makes it harder to debug also.
I found a statement why goto is bad on the net
the 'goto' statement, like many other features, is open to abuse; although in general (i.e. 99.99% of cases), there's simply no need for it, because the kind of 'jump' operations which programmers usually want to do can easily be encapsulated in a simple high-level flow control statement, such as if/else, for, while, switch, break, etc.

Plenty of "old" code still exists where programmers have used 'goto', and one of its problems when someone comes to maintain it, is that often a programmer will simply chuck in a harmless modification, but maybe will want to modify the flow a little too - one of the real problems with 'goto' is that changing the flow of a block which jumps around is actually very hard to do, unless you simply add in another 'goto'. the result is usually that code which started out relatively simple with only a couple of 'goto' jumps starts getting increasingly harder to follow, and turns into "spaghetti" code where nobody really knows what its doing, or why, or whether its behaviour is even correct in all cases.
I for one won't use goto at all. Most code can be broken into smaller functions which make goto obsolete, and I am from the old school of programming who used to use it all the time back in the old Spectrum days heh heh.

Asimov
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

Post Reply