1 / 9

GBK Programming 2 2009-10

GBK Programming 2 2009-10. Jordan Johnson Week 1, Day 2. Today’s plan. Greeting Networking, Continued: The Universe Clean-up. Goal. Add networking to the “Sea Battle” game. Requirements: Learn to write client (“world”) programs. Learn to write server (“universe”) programs. So far.

metea
Download Presentation

GBK Programming 2 2009-10

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GBK Programming 22009-10 Jordan Johnson Week 1, Day 2

  2. Today’s plan Greeting Networking, Continued: The Universe Clean-up

  3. Goal • Add networking to the “Sea Battle” game. • Requirements: • Learn to write client (“world”) programs. • Learn to write server (“universe”) programs.

  4. So far... • “Butterfly” simulation: • Butterfly moves from one computer to another, left to right on each individual screen. • (A butterfly icon is saved on the student server under Programming 2). • Messages: • Server  Client: ‘go(i.e. “You have the butterfly.”) • Client  Server: ‘done(“The butterfly has left me.”) • We’ve written the client.

  5. Review: The Client • To write the client: • Handlers sometimes return a package instead of just a world. • (make-packageworldmessage) • “Here’s the new world, and a message for the server.” • big-bang has new clauses: • on-receive – to say how to handle inbound messages. • register – to specify the address of the server. • name – to identify your world to the server by name.

  6. The Server • The server’s job is: • Keep track of the universe. • Respond to communication from worlds. • More specifically: • Maintain a list of connected worlds. • Add new worlds to the list. • Remove old worlds from the list. • When a world’s done with the butterfly, send the butterfly to the next world in line.

  7. The Server(cont.) • New types of data: • iworld – representation of a world (client) • The “universe” (server’s equivalent of “world”) • A universe is a listof[iworld] • (make-mailiworlds-exp) • A message to the given iworld. • bundle – server’s equivalent of a package • (make-bundleuniverse messages goners) • universe is the new state of the universe • messages is a listof[mail], to be sent to the worlds • goners is a listof[iworld], any worlds the server wants to disconnect.

  8. The Server(cont.) • Starting the server: • universe is the equivalent of big-bang: • (universe u0 (on-new hookup) (on-disconnect hangup) (on-msg listen)) • hookup : universe iworld bundle • How to handle a new world. • hangup : universe iworld  bundle • How to react when a world disconnects. • listen : universe iworld s-exp  bundle • How to behave when a world sends a message.

  9. Clean-up • Before you leave, please . . . • Log out. • Push in your chair. • Make sure you’ve got everything. • Make sure all trash ends up in the trash can.

More Related