Game Development Reference
In-Depth Information
radio. One computer sends data, and it blocks until the data is received by the other
side. When I say blocks, I mean exactly that the socket function that sends data
will not return until the data actually gets to the other side. You can see that this kind
of thing would be bad for servers or clients; you generally want to send and receive
data without waiting for the other side to get it and answer. This is the same, regard-
less of whether you use TCP or UDP.
Winsock or Berkeley?
You may have heard about Berkeley sockets, or the Berkeley implementation of the
sockets API. It
'
s called that because it was developed for the Berkeley UNIX operat-
ing system, and it is a commonly used implementation of the TCP/UDP protocols.
Of course, Microsoft developed an implementation of TCP/UDP as well, called Win-
Sock. You might wonder which one is better and debate endlessly about it, but I
ll
leave it to the experts and Internet forums. I like to use Berkeley sockets for multi-
player games, even under Windows. There
'
'
s a caveat to that, and I
'
ll clue you in on
it later.
Here is why I like to use Berkeley. When there
'
s a more standard API out there that
works, I tend to gravitate toward it. Forgive me for an example that will show my
age
s really a little like why Sony VHS won over Betamax. It had more to do
with the fact that more people were using VHS and nothing at all to do with the fact
that Betamax was a superior format. Actually, the people who were using VHS
represented the porn industry, and some say that ' s why it succeeded so quickly!
But I digress.
You are free to use Berkley-style sockets on a Windows machine, as I have done
throughout this chapter. Since space is such a premium
but it
'
God knows this topic is
heavy enough to give you cramps if you hold it too long
ll show you how to use
TCP to get your game running as a multiplayer game. You can investigate UDP once
you
I
'
'
ve mastered TCP. First, you have to know something about the Internet. After
all, you can
t send data to another computer on the Internet until you connect to
the computer, and you can
'
t connect to it until you can identify it uniquely from
every other computer on the Net.
You are free to use WinSock or Berkeley sockets to connect to other computers,
regardless of their choice of sockets implementation. As long as you send and receive
data formatted as both sides expect, you can set up network communications with
any other computer on the Internet. You can use your program to connect to Web
'
 
 
Search WWH ::




Custom Search