-
Notifications
You must be signed in to change notification settings - Fork 0
/
instructions.txt
106 lines (79 loc) · 2.25 KB
/
instructions.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
Node.js Workshop Steps
Prerequisites:
-Install Node.js
-nodejs.org
-Install Visual Studio Code
i. Explain server-side programming
- what is a host?
- what is a server?
- what is node.js?
1. Show javascript math in terminal.
2. Get set up:
- make a folder/download template folder
- open Visual Studio
- drag folder to Visual Studio
- new file (server.js)
3. "Hello World"
- console.log("hello world");
- open terminal
- js math
- show how to clear
- show cd (change directory)
- drag path from finder
- run server.js
- explain node modules (express)
- explain npm
4. Show npm website
- show where to find install command
5. npm init
6. npm install express --save
- highlight dependency
- show node modules dir
7. Show Express API
8. let express = require('express');
9. let app = express();
- show contents w/console.log(app)
10. let server = app.listen(3000);
- run server
- open localhost:3000
- localhost is address (like IP)
- 3000 is like a door
11. Make a public folder
- fill with index.html, sketch.js
12. app.use(express.static('public');
- show website (no more Cannot GET)
13. write some basic p5
- createCanvas(300, 300)
- background('pink');
- circle(mouseX, mouseY, 60);
14. npm install socket.io --save
15. let socket = require('socket.io');
- just like require express
- socket is now a function
16. let io = socket(server);
- store the result of the socket function
17. io.sockets.on('connection, newConnection);
- function newConnection(socket) {}
18. Visit socket.io website
- revisit difference between server and client
- copy socket.io client cdn url
- import cdn URL into html
19. Write code in client for socket
- let socket;
- socket = io.connect('localhost/ipAddress:portNumber);
20. log connection in newConnection function
- console.log('new connection @ ', socket.id);
21. send messages from client
- function mouseDragged()
- string to send
- object as package
- socket.emit('mouse', data);
22. receive messages from server
- socket.on('mouse', mouseMessage)
- function mouseMessage(data) {}
23. broadcast data back out
- socket.broadcasst.emit('mouse', data)
- (if global) io.socket.emit('mouse', data);
24. receive mouse data in client
- socket.on('mouse', newDrawing);
- function newDrawing(data) {}