MS .Net Framework with emphasis on online gaming

Download Report

Transcript MS .Net Framework with emphasis on online gaming

MS .Net Framework with
emphasis on online gaming
Ed Mucker
CS522
9 Dec 02
Overview
•
•
•
•
Online Gaming
MS .Net Framework
.Net Framework Class Library
Project Implementation
Online Gaming
• Architecture
– Server/Client (request/response through one point)
– Peer to peer (client responsible for sending all messages)
• Transport Protocol
– TCP - connection with server
– UDP - communication with other players (chat functions)
• Number of users
– Dependent on hardware/operating system (hundreds/thousands)
– Use of zones to distribute load (one zone per server)
– Threading techniques used to accommodate multiple users
MS .Net Framework
• Java architecture for Windows
– Common Language Runtime (JVM)
– MS Intermediate Language (Java Byte Code)
– Executable code machine dependent (MS OS only)
• CLR based languages
– C# (very similar to Java)
– VB .Net/Visual C++ .Net/JScript .Net
– Class interoperability between languages (CLS)
• CLR services
– Automatic garbage collection
– Assemblies/metadata (manifest)
MS .Net Framework Class
Library
• Namespaces
– Similar to packages in Java
– Consists of subordinate namespaces and classes
– Root namespace is “System”
• Common Subordinate namespaces
– IO, Net, Threading, Runtime.Serialization, Windows.Forms
• Use within CLR languages
– Syntax “using System.XXXX;”
– Similar to import statements in Java
– .Net/User defined
Project Implementation
•
•
•
•
Client/Server Architecture
Generate simple multi-user TCP socket program
Implementation done in C#
MS .Net Namespaces used
–
–
–
–
IO (reader stream)
Net (Network stream class)
Net.Sockets (TCP listener/client classes)
Threading (Thread class)
• Safe Code - Delegates (pointer to function)
• Asynchronous communication with multiple users
C# Programming Example - TCP Listener
using System.Threading;
public static void Main(){
//var declaration code
TcpListener listener = new TcpListener(8080);
listener.Start();
TcpClient client = listener.AcceptTcpClient();
ClientHandler cHandler = new ClientHandler();
cHandler.clientsocket = client;
ThreadStart t = new ThreadStart(cHandler.RunClient);
Thread clientThread = new Thread(t);
clientThread.Start();
listener.Stop();
}
C# Programming Example - RunClient()
using System.Text; using System.Net;
public static void RunClient(){
StreamReader read =
new StreamReader (clientSocket.GetStream());
NetworkStream write = clientSocket.GetStream();
string returndata = read.ReadLine();
System.Console.WriteLine(returndata);//write data to screen
byte [] datawrite = Encoding.ASCII.GetBytes(returndata);
write.Write(datawrite, 0, datawrite.Length);
clientSocket.Close();
}
References
• Multi-Player Game Programming (Barron)
• Understanding .Net (Chappell)
• Professional .Net Network Programming
(multiple authors)
• Mastering Visual C# .Net (Price)
Questions????