Network Status Indicator Data Binding to update scores Multiple players in one game LINQ to simplify coding Storyboard controlled animation Async socket.

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

Lecture 10 Sharing Resources. Basics of File Sharing The core component of any server is its ability to share files. In fact, the Server service in all.
KompoZer. This is what KompoZer will look like with a blank document open. As you can see, there are a lot of icons for beginning users. But don't be.
NEXT. Create Pages in Blogger Another top user-requested feature has just graduated from Blogger In Draft! Blogger now makes it easy to create Pages linked.
EEE436 / CS422 Final Presentation Group
Create great-looking signatures for your Get fancy—signatures with pizzazz The previous lesson showed you how to create a simple signature by using.
Add Sound Effects to a Presentation Add sound effects to a presentation Course contents Overview: This sounds easy Lesson 1: Play a sound file Lesson.
© 2009 Research In Motion Limited Methods of application development for mobile devices.
1 of 7 This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS DOCUMENT. © 2007 Microsoft Corporation.
Computers They're Not Magic! (for the most part)‏ Adapted from Ryan Moore.
Using Microsoft Outlook: Basics. Objectives Guided Tour of Outlook –Identification –Views Basics –Contacts –Folders –Web Access Q&A.
LEARN THE QUICK AND EASY WAY! VISUAL QUICKSTART GUIDE HTML and CSS 8th Edition Chapter 21: Publishing Your Pages on the Web.
Microsoft ® Office SharePoint ® Server 2007 Training SharePoint calendars I: Make the most of your team calendar Bellwood-Antis School District presents:
Windows 10. The New Microsoft Operating System to be released July 29 th. It’s not just a PC operating system, it’s a lot more, it includes phones,
Creating a Web Page HTML, FrontPage, Word, Composer.
Introduction to VBA. This is not Introduction to Excel We’re going to assume you have a basic level of familiarity with Excel If you don’t, or you need.
WorkPad 4 Quick Start WorkPad 4 Quick Start  Business Optix brings the rigor and discipline of business modelling and design into.
Web server and web browser It’s a take and give policy in between client and server through HTTP(Hyper Text Transport Protocol) Server takes a request.
Use my floppy disk. 1. copy short cut to desktop. 2.run NoAdHOSTS.exe 3. Surf without ad’s. 4.to reverse everything -edit out all url s you want to return.
131 Agenda Overview Review Roles Lists Libraries Columns.
Eucalyptus Virtual Machines Running Maven, Tomcat, and Mysql.
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
NOTE: To change the image on this slide, select the picture and delete it. Then click the Pictures icon in the placeholder to insert your own image. WEB.
Programming with Microsoft Visual Basic 2012 Chapter 12: Web Applications.
Introduction to Mobile Programming. Slide 2 Overview Fundamentally, it all works the same way You get the SDK for the device (Droid, Windows, Apple) You.
XP New Perspectives on Browser and Basics Tutorial 1 1 Browser and Basics Tutorial 1.
IT 211 Project Integration and Deployment Lab #11.
Moodle (Course Management Systems). Assignments 1 Assignments are a refreshingly simple method for collecting student work. They are a simple and flexible.
London April 2005 London April 2005 Creating Eyeblaster Ads The Rich Media Platform The Rich Media Platform Eyeblaster.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
E-Commerce: Introduction to Web Development 1 Dr. Lawrence West, Management Dept., University of Central Florida Topics What is a Web.
Introduction to Matlab & Data Analysis
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
Tutorial 121 Creating a New Web Forms Page You will find that creating Web Forms is similar to creating traditional Windows applications in Visual Basic.
PHP meets MySQL.
File Upload Competitive Analysis. Catalyst - Browse in-line Of interest:
Dreamweaver An introduction to Dreamweaver by a beginner who can show you the rudiments of quickly and easily creating a web site. An attempt to offer.
Chapter 4 Initial Configuration Tasks. Understanding the Initial Configuration Tasks window Microsoft now provides a new feature, the Initial Configuration.
FTP Server and FTP Commands By Nanda Ganesan, Ph.D. © Nanda Ganesan, All Rights Reserved.
DEV325 Deploying Visual Studio.NET Applications Billy Hollis Author / Consultant.
1. Chapter 25 Protecting and Preparing Documents.
NOTE: To change the image on this slide, select the picture and delete it. Then click the Pictures icon in the placeholder to insert your own image. WEB.
Add sound effects to a presentation Play a sound file In this lesson, you’ll learn how to insert a sound file of your own or a sound effect from the clip.
Downloading and Installing Autodesk Revit 2016
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
Microsoft ® Office PowerPoint ® 2003 Training Playing sound [Your company name] presents:
Webmasters’ Guild Word Training. Making Better Word 2007 (and 2003) Documents Styles…Images…Lists Oh my!
It’s time to write and send your first message using the new Outlook. In a new message, first get oriented to the Ribbon. The Message tab is on.
Build a database V: Create forms for a new Access database Overview: A window into your data So far in this series of courses, you’ve built tables, relationships,
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
1 Terminology. 2 Requirements for Network Printing Print server Sufficient RAM to process documents Sufficient disk space on the print server.
Compare and Contrast : Blackboard & a Personal Web Page www3.ltu.edu/~s_schneider/howto/faculty.htm You’ll find this presentation (and another) here :
Unit 3: Text, Fields & Tables DT2510: Advanced CAD Methods.
1 Getting Started with C++ Part 1 Windows. 2 Objective You will be able to create, compile, and run a very simple C++ program on Windows, using Microsoft.
Chapter 27 Getting “Web-ified” (Web Applications) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Netprog: Client/Server Issues1 Issues in Client/Server Programming Refs: Chapter 27.
VB.NET and Databases. ADO.NET VB.Net allows you many ways to connect to a database. The technology used to interact with a database or data source is.
Working with ASP.NET Controls What is ASP.NET Using server controls in your pages Allowing users to create their own accounts Creating a login page Letting.
Spaso Lazarević Microsoft MVP Nova banka ad Banja Luka Building business application using Visual Studio 2013 LightSwitch.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
TELEPORT PRO Website to Hard Drive Completely download a website, enabling you to “Browse Offline” at much greater speeds than if you were to browse the.
Using the AFRESH software Ruaraidh Dobson University of Aberdeen V1.0 27/04/2016.
Weebly Elements, Continued
Building a User Interface with Forms
Microsoft Word Reviewing Documents.
August 17, 2015 J. Boles, J.Burnias and M.Garcia Office 2013
Issues in Client/Server Programming
FTP AND COMMAND PROCESSING IN FTP
Windows Forms in Visual Studio 2005: An in-depth look at key features
Presentation transcript:

Network Status Indicator Data Binding to update scores Multiple players in one game LINQ to simplify coding Storyboard controlled animation Async socket code Picture Hunt Silverlight Socket Demo Automatic connection retry About the game

Running the Picture Hunt game demo Simplest way: start the “RunDemo.bat” file It starts the three components of the demo: – the Silverlight Policy Server Go to directory (cd) “SilverlightPolicyServer” Start “Run.bat” – Start the Picture Hunt Game Server Go to directory (cd) “PictureHunt\PictureHuntServer” Start PictureHuntServer.exe – Start the Silverlight game Go to directory (cd) PictureHunt\PictureHunt\Bin\Debug Start PictureHuntTestPage.html

Overall Architecture The server computer has more pieces: 1.The game HTML file served up by a running web server 2.The running game server program 3.A bunch of marked-up images in the right directory 4.The running socket policy server program On the client computers: A running Web browser with the Silverlight game

Programming hint: Common files for clients and servers The Silverlight IDE (Microsoft Visual Web Developers 2010 Express) will copy files into the project directory when you “add existing item” to your Silverlight project That’s not what I wanted! I wanted a single file in both the Server and Game projects. In the end, I edited the.csproj file by hand to reference files in the server project.

Policy Server details Like many web-facing technologies, Silverlight imposed some security restrictions on Sockets. You need to run a Silverlight Policy Server on port 943 (or other ports). The System.Net team has a simple policy server as a code snippet at

Multiple Players Multiplayer games are ideal for sockets: Anyone can click at any time The server can update anyone at any time Http style “request/response” doesn’t work well for these types of problems. It’s the server that has most multiplayer code; each client of course only handles itself

Async Socket Code Connect Read and Write Closing

Connecting var s = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); var e = new SocketAsyncEventArgs(); e.RemoteEndPoint = new DnsEndPoint(serverName, 4529); e.Completed += OnConnected; s.ConnectAsync(e); Async Socket Code

Writing Picture Hunt makes a list of ArraySegments, and then writes them out with “SendAsync”. The WriteCompleted doesn’t actually do anything for this application var senddata = new List >(); senddata.Add(new ArraySegment (header)); if (data != null) senddata.Add(new ArraySegment (data)); var writeEventArgs = new SocketAsyncEventArgs(); writeEventArgs.Completed += WriteCompleted; writeEventArgs.BufferList = senddata; socket.SendAsync(writeEventArgs); Async Socket Code

Handling message boundaries TCP/IP is a stream protocol: it doesn’t respect your game message boundaries. For example: the game server sends three messages: But the game might get these messages: Why? TCP/IP data doesn’t preserve message boundaries: it’s a stream of data (like a file: you can write 10 bytes and 10 bytes and 10 bytes, and then read 8 bytes and 15 bytes and 7 bytes) Solution: Your program has to track the message boundaries Async Socket Code

Serializing Data over a Network Different people have different styles for serializing data. Picture Hunt has hand-made code for serialization. Each Command that has extra header fields has to implement “InitHeader()” to write them out into a BinaryWriter. Data is read in with the CommandReader class (which also handles message boundaries). CommandReader has to know about every class and every opcode; this is written by hand ‘htonl’ converts host to native format (this lets my program work on any system) Async Socket Code

Closing Close your socket when you’re done: closingSocket.Shutdown(SocketShutdown.Both); closingSocket.Close(); closingSocket = null; Async Socket Code

Network Status Style: Discrete Network Status Picture Hunt uses a Discrete Network Status: a little icon of the network conditions with no text and absolutely no dialog boxes Network Status Indicator The Discrete style is often a good choice. Other choices are Per-task dialog: show multiple activities related to a task (e.g., downloading) User-selected dialog: similar, but is shown only when user asks. Is appropriate when networking isn’t a primary part of the user’s work UI replacement: when offline, switch interface. Is appropriate when the app has no off-line capabilities (which is rare)

Network Status States Unstarted Goes to “Started” when the user clicks “Connected”; program is told to StartNetworkConnection() Started Goes to “OK” if a connection can be made Goes to “FailNl” if a connection cannot be made Ok Goes to “Fail” if a socket read fails to read Fail Sets a timer to switch to “Retry” Retry The program is told to StartNeworkConnection() Goes to “Ok” if the connection works and “Fail” if it does not FailNl Sets a timer to switch into “RetryNl” RetryNl The program is told to StartNetworkConnection() Goes to “Ok” if the connection works and “FailNl” if it does not

Automatic Connection Retry People move their laptop computers a lot more than they used to. Your program has to handle Network Transitions smoothly: Always retry on failures Use the network status (and not an emergency dialog) Transitions are common: the user doesn’t need a big reminder

Adjust the retry times when there’s no connection At start: retry every 2 seconds Then every 15 seconds Later, retry every hour Why? The game doesn’t want to overuse the network. There’s a validation routine to make sure the table of adjustments is reasonable. All this is in NetworkStatus.cs – the GetRetryTime() and the associated RetryTime list and DelayTime class. There is also a validation routine.

And one more thing: Network Transitions You should also detect NetworkAddressChanged and pro- actively set up a new socket. New socket usable? Use it and drop to the old one New socket not usable? Drop it and keep the old one. Just be careful when you’ve got two sockets open at once. The NetworkAddressChanged event is pretty chatty; you’ll need to “de-bounce” it with a small timer. With a discrete network status style, you don’t tell the user that you’re even trying it.

Hints: debugging new connections Quick test (laptop): start with Wi-Fi and no Ethernet and run the game. Then plug in Ethernet, wait five seconds, and turn off your WiFi. The game should already be connected to Ethernet. I made life easier for myself by adding in a “New Network” button for debugging. Every time I clicked it, it would try a new network. I also added a server command to reject all new players – this helps validate that the code is robust. The game should accept the new connection failure and keep on using the old one. Not all new connections work!

LINQ to simplify coding The game demo uses LINQ in several places to make the code easier to write and understand. For example, when the user can asks for a hint for an area to click; the following game server code finds an area to show: Area a = (from area in areas where area.HitBy == null && area.Name == CurrLookFor select area).DefaultIfEmpty(null).FirstOrDefault(); The resulting single Area is now either a good candidate to return, or is null. Reading a LINQ book really helped me get started.

Data Binding to Update Score Data Binding is a way to automatically link your data to a UI element When you update your data, the UI is updated, too! Can work the other way as well (UI  Data)

Data Binding Code public class PlayerScore { public int index { get; set; } public string name { get; set; } public int score { get; set; } } public ObservableCollection playerScores { get; set; }

Data Binding Code (part 2) About that code… 1.Everything needs to be public 2.Everything needs to be a property 3.PlayerScore does not implement INotifyPropertyChange, so only clear+replace will show up (e.g., can’t take an existing score and change it; have to remove all and add back in) I couldn’t have done it without Petzold’s Windows Phone book (free download; got to )

XAML (UI) part of Data Binding

Storyboard Controlled Animation Adding animation was easy and made a big improvement in the game Add items in the XAML; set the TargetName to the thing to animate and the TargetProperty to the property to animate (usually opacity or position) In the game code, call ___Storyboard.Begin() to trigger the animation

Storyboard Controlled Animation Animations include: The title The instructions The player list The “look for” (both new words and when there’s a winner) The winner text MSDN was enough to make it work