GBK Programming 2 2009-10 - PowerPoint PPT Presentation

metea
gbk programming 2 2009 10 n.
Skip this Video
Loading SlideShow in 5 Seconds..
GBK Programming 2 2009-10 PowerPoint Presentation
Download Presentation
GBK Programming 2 2009-10

play fullscreen
1 / 9
Download Presentation
GBK Programming 2 2009-10
71 Views
Download Presentation

GBK Programming 2 2009-10

- - - - - - - - - - - - - - - - - - - - - - - - - - - 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.