[ Pobierz całość w formacie PDF ] .The reason is that there are three types of networks called class A, class B, and classC.Each class uses a certain range of possible IP addresses, severely limiting the total possiblecombinations.For example, class C networks use IP addresses in the range 192.x through223.255.255.x.Class C networks use the first three bits to identify the network as class C, which leaves21 bits for identifying a computer on the network.The value 221 is a total of 2,097,152 possibleaddresses; as of 2002, over fifty percent of those have been assigned to computers that are alwaysonline.But it gets worse class B networks have a total of 16,384 combinations and class A networksonly have 128.Fortunately, new legislation is changing all that.For more information check out theAmerican Registry for Internet Numbers (http://www.arin.net).There are two kinds of addresses: For those machines that are always on the Internet there are staticaddresses that never change.For those computers that have dial-up connections or that aren't regularlyon the Internet there are dynamic addresses that are different each time the computer connects.With all the phone numbers, bank accounts, combination locks, secret passwords, and shoe sizes,there isn't much room left over in most people's memories for a collection of IP addresses.So in orderto make things a little more user friendly, host names were introduced.A host name such ashttp://www.flipcode.com or http://www.gamedev.net represents the four-number address.If the IP325address changes, the host name keeps working.A host name has to be resolved back into the IPaddress before it can be used to make a connection attempt.In order to resolve a host name, thecomputer trying to resolve must already know the address of a Domain Name Server (DNS).It contactsthe DNS and sends the host name.The DNS server responds by returning the numeric IP address ofthe host.With so many programs running on so many different computers around the globe, there has to be away to separate communication into different "channels," much like separate phone lines or TV stations.Inside any Winsock-compliant computer are 65,534 imaginary ports to which data can be sent.Somerecognized protocols have default ports HTTP uses port 80 and FTP uses port 21 (more on protocolsin a moment).Any program can send data to any port, but if there's no one listening the data will beignored, and if the listening program doesn't understand the data then things could get ugly.In order tolisten or transmit data to a port, both machines must begin by initializing Winsock, a standard library ofmethods for accessing network firmware/hardware.Winsock is based in part on UNIX sockets so mostmethods can be used on either type of operating system without need for rewriting.Once Winsock hasbeen initialized, the two machines must each create a socket handle and associate that socket with aport.Having successfully completed socket association, all that remains to do is transfer data and thenclean up when you're done.But your problems are just beginning.Once you've finished all thefundamental communication code there should only be one thing on your mind: speed, speed, and morespeed.Network ModelsIn order to make games run smoothly some kind of order has to be imposed on the Internet; someclearly defined way of making sure that every player in the game sees as close to the same thing aspossible.The first thought that leaps to mind is "connect every machine to every other machine!" This isknown as a peer-to-peer configuration and it sounds like a good configuration.In fact it was used insome of the first networked games.However, as the number of players rise, this peer-to-peer modelquickly becomes impractical.Consider a game with four players.Each player must have threeconnections to other players for a total of six connections.Each player also has to send the same datathree times.Hmm.Dubious.Now consider the same game with six players.Each player has to send thesame data out five times and there are a total of 15 connections.In an eight-player game there are 28connections.Try it yourself the equation isAnother method might be to arrange all the players in a ring, with each player connected to two othermachines.This sounds a bit better because there are only (P + 1) connections and each player only hasto send data once, clockwise around the ring.My computer tells your computer, your computer tells hercomputer, and so on around the ring until it comes back to me at which point I do nothing.But consider326the amount of time it takes to send information from one computer to another.Even if a computer sendsdata in both directions at once it will still take too long for data to travel halfway around the ring.Thingscan become pretty complicated if one of the player's computers suddenly crashes or leaves the gameall the data that it had received but not yet transmitted to the next machine in the ring suddenlyvanishes, leaving some machines with one version of the game and some with another.Figure 7.2: Peer to peer, ring, and client/server network configurationsThe most popular design is a client/server configuration, which might look like a star because everyplayer is connected to a powerful central computer.This central computer is the server and it makessure everyone is synchronized and experiencing the same thing.There are, at most, P connections in aclient/server configuration and the clients only have to send data once
[ Pobierz całość w formacie PDF ]
zanotowane.pldoc.pisz.plpdf.pisz.plhanula1950.keep.pl
|