Creative Computing

Joel Gethin Lewis

Unit 4 / Block 2: "Coding for Collaborative Web Development": Lecture 2: Functions, Websockets and Socket.IO

Have you taken the register first? Are you recording?

What I'm going to talk about today:

  1. What questions to do you have for me?
  2. New functionality around Functions - arrows, promises and async.
  3. More functionality - Fetch
  4. Matt DesLauriers' node.js/p5.js demos.
  5. What are Websockets?
  6. What is Socket.io? Building a shared canvas, building a chat room.
  7. Matt DesLauriers' socket.io demos.
  8. Golan Levin's and Char Stile's socket.io demos.
  9. What questions to do you have for me?

0. What questions to do you have for me?

  • What questions to do you have for me?
  • What are your concerns? What are you worried about? What do you want to ask but you are embarrassed?
  • All questions allowed!
  • 5 minutes to message me on Slack in private.
  • This idea came from Zach Lieberman. He does this exercise at the start of every session of School of Poetic Computation in New York.

1. New functionality around Functions - arrows, promises and async.

2. More functionality - Fetch.

3. Matt DesLauriers' node.js/p5.js demos.

4. What are Websockets?

  • Quoting from MDN: "The WebSocket API is an advanced technology that makes it possible to open a two-way interactive communication session between the user's browser and a server. With this API, you can send messages to a server and receive event-driven responses without having to poll the server for a reply."
  • This means you can ask for some data from the server (or send it), and specify a function in your code to run when the reply comes in, while the rest of your code is running.
  • Before these kinds of technologies, code would have to constantly ask again and again (or "poll") for information. Causing lots of unnecessary network traffic and making the code much more complicated.

5. What is Socket.io? Building a shared canvas, building a chat room.

6. Matt DesLauriers' socket.io demos.

7. Golan Levin's and Char Stiles socket.io demos.

  • Bare Socket.io demo: "hit any key besides space to add a random number from 0 to 24 and space to display the average".
  • Chatroom: "chatroom".
  • Drawing game: "Multi-player drawing game using Socket.io & p5.js".
  • Agar.io clone: "A simple implementation of the game agar.io".
  • What else could you use these examples for?

8. What questions to do you have for me?

  • What questions to do you have for me?
  • What are your concerns? What are you worried about? What do you want to ask but you are embarrassed?
  • All questions allowed!

Thanks!