Flight Simulation Client/Server

Slides:



Advertisements
Similar presentations
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Advertisements

A CHAT CLIENT-SERVER MODULE IN JAVA BY MAHTAB M HUSSAIN MAYANK MOHAN ISE 582 FALL 2003 PROJECT.
Review of Java Applets Vijayan Sugumaran Decision and Information Sciences Oakland University.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 16 Applets.
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 1 Let’s get started. Let’s start by selecting an architecture from among.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
Review CSC 171 FALL 2004 LECTURE 21. Topics Objects and Classes Fundamental Types Graphics and Applets Decisions Iteration Designing Classes Testing and.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
Networking with Java CSc 335 Object-Oriented Programming and Design Spring 2009.
Applets  The Applet Class  The HTML Tag F Passing Parameters to Applets.
NET0183 Networks and Communications Lecture 31 The Socket API 8/25/20091 NET0183 Networks and Communications by Dr Andy Brooks Lecture powerpoints from.
Networking: Part 2 (Accessing the Internet). The UI Thread When an application is launched, the system creates a “main” UI thread responsible for handling.
Chapter 34 Java Technology for Active Web Documents methods used to provide continuous Web updates to browser – Server push – Active documents.
Multi-Threaded Application CSNB534 Asma Shakil. Overview Software applications employ a strategy called multi- threaded programming to split tasks into.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
(c) University of Washington08-1 CSC 143 Models and Views Reading: Ch. 18.
Object Oriented Programming Lecture 4: Refactoring, An Applet Example, Idiom - Animation applets, Introduction to the Laboratorial exercise www2.hh.se/staff/jebe/oop2005/
SIMPLE PROBLEM SOLVING in Java: a Problem Set Framework Viera K. Proulx Richard Rasala Jason Jay Rodrigues CCSCNE 2002 Conference.
1 Web Based Programming Section 8 James King 12 August 2003.
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
1 Chapter 28 Networking. 2 Objectives F To comprehend socket-based communication in Java (§28.2). F To understand client/server computing (§28.2). F To.
Li Tak Sing COMPS311F. RMI callbacks In previous example, only the client can initiate a communication with the server. The server can only response to.
Chapter 14 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
Li Tak Sing COMPS311F. Case study: a multithreaded chat server The source contains 3 files: ChatServer //the chat server ChatThread //the thread on the.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 33 Networking.
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
Socket Programming Ameera Almasoud
Running a Forms Developer Application
Threads in Java Two ways to start a thread
MPEG-4 Binary Information for Scenes (BIFS)
Working in the Forms Developer Environment
WWW and HTTP King Fahd University of Petroleum & Minerals
Servlet Fudamentals.
Architecture Concept Documents
Object-Oriented Systems Analysis and Design Using UML
Pre assessment Questions
AJAX.
Distributed Computing, M. L. Liu
Distributed Computing, M. L. Liu
Predefined Dialog Boxes
Clients and Servers 19-Nov-18.
Programming in Java Text Books :
Introduction to Behavioral Patterns (1)
Clients and Servers 1-Dec-18.
L3. Necessary Java Programming Techniques
L3. Necessary Java Programming Techniques
Object Oriented Programming
Chapter 40 Remote Method Invocation
Servlet APIs Every servlet must implement javax.servlet.Servlet interface Most servlets implement the interface by extending one of these classes javax.servlet.GenericServlet.
Java applets 1/3/2019.
Java Threads (Outline)
Threads Chapter 4.
Java Threads (Outline)
Channels.
Design pattern Lecture 9.
Chapter 46 Remote Method Invocation
Chapter 46 Remote Method Invocation
Channels.
An Introduction to Internetworking
Model, View, Controller design pattern
Channels.
JAVA APPLET PREPARED BY Mr. Jahanzaib Ahmed
Clients and Servers 19-Jul-19.
APPLET PROGRAMMING.
Clients and Servers 13-Sep-19.
Presentation transcript:

Flight Simulation Client/Server Malcolm Mumme 4/25/2019

Introduction Using Java features to program Client/Server applications Threads, Sockets, inheritance, &c. (all page number references are to the textbook) 4/25/2019

Topics of Discussion Java Threads and Strand Threads Socket input buffering with ReEnumerator Simulation state updates with Entity and SimMonitorMessage Output Synchronization Managing clients in SimEngine Display updates using SimulationClient and Radar/WinDisplay 4/25/2019

Java Threads and Strand Threads Text implies that Threads may outlive the objects that contain them. (p. 842) This is not consistent with the usual approach to objects Define Strand class as a more OO Thread Strand interface similar to Thread: new Strand( (Runnable)this ); Strand will automatically start the thread at construction and stop the thread upon finalization (p. 472) 4/25/2019

Java Threads and Strand Threads A class’s finalizers can be overriden by subclasses, parent finalizers are not automaticaly called as with constructors(p. 516) Avoid this problem by using a helper final class StrandThreadContainer who’s finalize() method stop()s the Thread. 4/25/2019

Socket input buffering with ReEnumerator Why Socket input buffering? A multi-user server must not be forced to wait on an individual Socket An Enumeration(p. 769) is a convenient way to package a sequence of messages A ReEnumerator packages a sequence of Enumerations 4/25/2019

Socket input buffering with ReEnumerator A Server Client1 in in Stream Socket Socket out out Stream Client2 in in Socket Socket out out A multi-user server must not be forced to wait on an individual Socket 4/25/2019

Socket input buffering with ReEnumerator A Server Client1 in in Stream Socket Socket out out Stream Client2 in in Socket Socket out out A multi-user server must not be forced to wait on an individual Socket 4/25/2019

Socket input buffering with ReEnumerator an Object An Enumeration nextElement() an Object an Object hasMoreElements() an boolean An Enumeration(p. 769) is a convenient way to package a sequence of messages 4/25/2019

Socket input buffering with ReEnumerator A ReEnumerator contains a Strand Thread which keeps the main thread from having to wait on a Stream nextElement() returns an Enumeration That Enumeration supplies those messages that have already been buffered. MessageEnumeration is an extended Enumeration interface for this program that has a method nextSimMonitorMessage() 4/25/2019

Socket input buffering with ReEnumerator an Enumeration A ReEnumerator buffer nextElement() an Enumeration an Enumeration buffering Strand a boolean hasMoreElements() A ReEnumerator packages a sequence of Enumerations 4/25/2019

Socket input buffering with ReEnumerator A MessageEnumerator wraps(p. 725) an input Stream with a MessageEnumeration MessageReEnumerator is a special ReEnumerator that works with a MessageEnumeration …= new MessageReEnumerator( new MessageEnumerator( in ) ) wraps and buffers the stream 4/25/2019

Simulation state updates with Entity and SimMonitorMessage Each simulated thing has a corresponding Entity Object in the SimEngine Each Entity contains several simulation parameters relating to it( position, velocity, orientation, shape, color, name,spin rate &c. ) An Entity can step() itself forward in time to do it’s part of the simulation 4/25/2019

Simulation state updates with Entity and SimMonitorMessage A SimMonitorMessage communicates partial update information about an Entity and can update(Entity) There is a subclass of SimMonitorMessage for each parameter in an Entity A SimMonitorMessage can be read from a DataInputStream and can update an Entity A SimMonitorMessage can be constructed from an Entity and can write itself to a DataOutputStream … 4/25/2019

Output Synchronization A SimMonitorMessage writes itself to a DataOutputStream in many little pieces. There is more that one Strand(Thread) in the SimulationServer in which this may occurr. This must always be done with “synchronized” methods(p. 851) : public synchronized static void sendAllMessages( … ) public synchronized static void sendUserControlMessages(…) … 4/25/2019

Output Synchronization In Thread A, SimMonitorMessage X writes itself to out OutputDataStream out In Thread B, SimMonitorMessage Y writes itself to out X0 X1 X2 Y0 X3 Y1 X4 X5 … … in many little pieces. …There is more that one Strand … in which this may occurr. 4/25/2019

Managing clients in SimEngine The SimEngine starts running a simulation Strand at construction The SimulationServer Object adds clients to the SimEngine by invoking the addMember(Socket) method Clients may leave at any time on request or by just aborting and causing an IOException on a Socket The SimulationServer may destroy the SimEngine at any time in response to the “Quit” button 4/25/2019

Managing clients in SimEngine When the SimulationServer Object adds clients to the SimEngine by invoking the addMember(Socket) method, A new simulation Entity corresponding to the client must be created and initialized All existing clients must be updated adding the new Entity The new client must be informed of it’s corresponding Entity The new client must be downloaded with the entire simulation state 4/25/2019

Managing clients in SimEngine A client may quit at any time. The SimEngine may be informed of this by: 1: a request from the client 2: an IOException on that clients Socket The corresponding Entity must be removed, and all remaining clients must be then informed of that. When the client requests to quit, the SimEngine also informs the same client (as well as all the remaining clients) of it’s Entity being removed 4/25/2019

Managing clients in SimEngine The SimulationServer may destroy the SimEngine at any time in response to the “Quit” button A client may quit at any time. The SimEngine has a finalize() method which does the following: Each Entity must be removed and each corresponding client must be then informed of that. 4/25/2019

Display updates using SimulationClient and Radar/WinDisplay A SimulationClient connects to the SimulationServer with a Socket in the usual way(p. 862) The simulation state is duplicated on each client using the same class Entity used on the server The SimMonitorMessage class is used for all messages both from and to the SimulationClient 4/25/2019

Display updates using SimulationClient and Radar/WinDisplay A SimulationClient must receive all messages from the SimulationServer It must create an Entity Object when informed of it’s existence It must update the corresponding Entity when it receives a SimMonitorMessage from the SimulationServer It must remove an Entity for which it receives a “Quit” message 4/25/2019

Display updates using SimulationClient and Radar/WinDisplay A SimulationClient must remember to which Entity it corresponds It must render visual images from the point of view of it’s corresponding Entity It must update it’s Entity and the SimulationServer whenever the user changes a control on the Applet Window It must quit when it’s Entity is removed by the SimulationServer 4/25/2019

Display updates using SimulationClient and Radar/WinDisplay A SimulationClient display images are rendered in the WinDisplay Applet that maintains the primary display area(by means of the renderAll() method). Within renderAll ,a polygonal model is extracted from each Entity The light on each polygon is adjusted according to it’s orientation. Each polygonal model is geometricaly manipulated to it’s relative orientation and location as it should appear on the display. 4/25/2019

Display updates using SimulationClient and Radar/WinDisplay A shadow polygon at altitude 0 is created in some cases. Each polygonal model is clipped to remove parts that would not be visible within the display window After all polygonal models are geometricaly processed, they are reordered to approximate a visibility algorithm. All polygons are then rendered to a clean Image using the fillPolygon method, which is then copied to the window by drawImage to minimize flicker. 4/25/2019

Potential improvements Add a dialog to the client for obtaining the Server host name Get some better scenery Correct the visibility algorithm Add realistic flight dynamics Improve the appearance of planes … 4/25/2019

What This Means With Sockets and Threads, you can do fun stuff 4/25/2019