Network Essentials Essay

Submitted By zl1002
Words: 776
Pages: 4

Multiplayer Online Games
Concepts and Network Essentials

Module Aims l To

introduce students to:

l Massively

multi-player gaming technologies l Network programming using sockets l Upon

successful completion of this module, students should be able to: l Develop

multi-player games with network play

Lets not start here

Lets start here

Network games in its simplest form

è ç Fancy a game of tic-tac-toe? è Ok, I’m O’s, 5 ç 4 è 3 ç 7 è 1 Error connection failure: game reset

What can you see here?

Key concepts l Two

(or more) applications communicating l A means of communication (mouse-hole) l Initial connection/agreement l Message passing (paper) l Sending of game information l Network errors/cheating Not shown: l Addressing (this was just 1-1)

Questions?

Now lets bring this into the technical world

Technical terms you need to know l OSI

Protocol Stack l Socket l TCP, UDP, Multicast l IP Address & Port l Messages & Streams

OSI Protocol Stack l The protocol stack is was way to break down networking into layers l HTTP,FTP

Each layer has a set of responsibilities Using either UDP/IP or TCP/IP

l

We will work at level 4 l What this means to us l l

It means that we do not need to worry with the internal details of the networking There is no difference in sending a message to an adjacent machine or a machine in a different country (WRT code)

App

App

Meet the Sockets l A

socket allows sending of binary data across the network l Three types l TCP/IP l UDP/IP l UDP/IP

Multicast (not covered in practicals)

TCP/IP l l l l

Telephone Guaranteed delivery 1-1 two-way connection Connect to mainline, then redirected Client

Mainline

Servicer

UDP/IP l l l

Throwing a message Message sent (one way) to a target Delivery not guaranteed l But usually gets there

l

No explicit connection required

UDP/IP Multicast l l l l

Shouting messages Message sent to many targets Delivery not guaranteed No explicit connection required

IP Address & Port l IP Address identifies a machine
AA.BB.CC.DD l Each part is 0..255 l l

Port identifies a socket on the machine
Ports 1-1024 are for system use l We will use port 2000+ l Messages l l

l

UDP is a message based protocol The socket sends a array of bytes in a message to a given address The socket gets messages containing the senders address & the data

0001

0010

Streams l l

TCP is a stream based protocol It appears like a bidirectional stream of bytes l With no beginning, end or markers

l

Sockets send and receive bytes via the streams

Common Code (Java) l Get

address of host/own machine

InetAddress addr = InetAddress.getLocalHost(); // Own Machine InetAddress addr = InetAddress.getByName( ‘example.com’ ); // Other Machine

UDP Code (Java) l l

Create the UDP Socket
DatagramSocket socket = new DatagramSocket(portNum);

Create the UDP Packet
String s = "This is a test"; byte[] data =