====== Game Networking ====== ---- ===== Networking Basics ===== * Networking: shifting bits from point A to point B * Internet Protocol (IP) - Network layer * The [[http://en.wikipedia.org/wiki/OSI_model|Open Systems Interconnection model (OSI model)]] defines 7 abstraction "layers" for a communications system. * Puts data bits into a network packet that tells where the packets need to go * Not reliable by itself * User Datagram Protocol (UDP) - Transport layer * Uses IP for addressing and routing * Divides the bits of a packet into groups and sends them in several successive packets * Transmission Control Protocol (TCP) - Transport layer * Guarantees reliable delivery in the order in which the packets were sent * Uses IP for addressing and routing; hence better known as TCP/IP * Socket - An endpoint in the IP protocol for sending and receiving data between networked computers * Packet - A block of data sent over the network * transmits the identities of the sending and receiving stations, error-control information, and a payload (data or messages) {{ http://www.cisco.com/web/about/security/images/csc_child_pages/white_papers/ip_packet.jpg }} * Port - Where information goes into or out of a networked computer * Ports for major networked services are standardized. * HTTP is port 80, MySQL is port 3306, SSH is port 22, etc. * See http://www.iana.org/assignments/port-numbers for list of port numbers ===== Network Design (Topologies) ===== * Most common: client-server {{ http://i.msdn.microsoft.com/Bb153244.client-server(en-us,VS.85).gif }} * Other designs: * Which one of these comes closest to a P2P (peer-to-peer) model? {{ http://whatis.techtarget.com/WhatIs/images/topology.gif }} ===== Networking in Java ===== * Package: java.net.* * You will almost certainly need the package java.io.* for Java networking * Useful packages: * [[http://docs.oracle.com/javase/1.5.0/docs/api/java/net/Socket.html|Socket]] * [[http://docs.oracle.com/javase/1.5.0/docs/api/java/net/ServerSocket.html|ServerSocket]] * Implementing a client: see [[http://rockhopper.monmouth.edu/~jchung/cs498gd/fa09/examples/SocketTest.java|SocketTest.java]] * Implementing a server: see [[http://rockhopper.monmouth.edu/~jchung/cs498gd/fa09/examples/SingleEchoServer.java|SingleEchoServer.java]] ==== A Simple Networked Game Example ==== * Download [[http://rockhopper.monmouth.edu/~jchung/cs498gd/fa11/labs/NetworkedGame.zip|NetworkedGame.zip]] * //SimpleGameServer.java// is a standalone server meant to be compiled and run separately. * //PlayerClient.java// is currently set to connect to //HOST=10.1.13.147 (cslin13.monmouth.edu)//. * If you run //SimpleGameServer// on a computer other than cslin13, you'll need to change what HOST is set to in //PlayerClient.java//. === A Game Server ==== * Manage multiple players * Have some capacity * routine must exist to determine whether server is full * Add and remove players * Send data to one or multiple players * Process players' inputs === A Game Client === * Connect to game server * Read and process data from server * Send data to server (for it to process) * Render the content ===== Diagnostic Tools ===== * Netcat - The network "Swiss-army knife;" reads and writes data across TCP or UDP network connections * [[http://www.wireshark.org/|Wireshark]] - For sniffing and analyzing packets * [[http://www.nmap.org/|nmap]] - Network mapper; determines open ports and server software installed on a machine ----