# Courese-Websocket/SQL DB https://www.facebook.com/ccckmit/videos/1853968648287309/?idorvanity=266037214366597 https://www.facebook.com/ccckmit/videos/456773166537788?idorvanity=266037214366597 # Web socket https://deno.land/x/websocket@v0.1.4 Server ```typescript import { WebSocketClient, WebSocketServer } from "https://deno.land/x/websocket@v0.1.4/mod.ts"; const webServerSocket = new WebSocketServer(6699) console.log(`Start at http://127.0.0.1:6699`) webServerSocket.on("connection",function(socketClient:WebSocketClient){ socketClient.on("message",function(message:string){ console.log(message); socketClient.send(message) }) }) ``` Client ```typescript import { WebSocketClient, StandardWebSocketClient } from "https://deno.land/x/websocket@v0.1.4/mod.ts"; const serverIP = "ws://127.0.0.1:6699"; const clientSocket:WebSocketClient = new StandardWebSocketClient(serverIP) clientSocket.on("open",async function(){ console.log("connection have been down !!!") clientSocket.send("meowhecker Client") console.log("if you want to terminate. Please enter close ") while (1) { const msg = await prompt(">") if(msg == "close") break clientSocket.send(msg) } }) clientSocket.on("message", function (message: string) { console.log(message); }); ``` ![](https://i.imgur.com/RSYOVkV.png) Version 2 Server ``` import { WebSocketClient, WebSocketServer } from "https://deno.land/x/websocket@v0.1.4/mod.ts"; // //Record has conneted clientSocket // const clientMap = new Map() let clientSocketList:any = []; const webServerSocket = new WebSocketServer(6699) console.log(`Start at http://127.0.0.1:6699`) webServerSocket.on("connection",function(socketClient:WebSocketClient){ // clientMap.set(socketClient,null) clientSocketList.push(socketClient) socketClient.on("message",function(message:string){ console.log(message) for (let i=0;i<clientSocketList.length;i++){ console.log(`send message to ${clientSocketList[i]}`) clientSocketList[i].send(message) } }) }) ``` Client ``` import { WebSocketClient, StandardWebSocketClient } from "https://deno.land/x/websocket@v0.1.4/mod.ts"; const serverIP = "ws://127.0.0.1:6699"; const clientSocket:WebSocketClient = new StandardWebSocketClient(serverIP) clientSocket.on("open",async function(){ console.log("connection have been down !!!") const clientId = await prompt("Nick Name > ") clientSocket.send(`${clientId} has connected`) console.log("if you want to terminate char room. Please enter quite ") //chat while (1) { const msg = await prompt(">") if(msg == "quite") break clientSocket.send(`${msg} from (${clientId}`) } }) clientSocket.on("message", function (message: MessageEvent) { console.log(`Receive:${message.data}`) }) ``` ---- # White Board JavaScript 匿名函数 if (document.load){execute coed} ```typescript (function() {}) ``` ```typescript user strice ``` # Database ## Normalization - Mysql - postgreSQL ## Denormalization - MongoDB - JsonDB Sample: ``` let userTable =[] userTable.push({username:"meowhecker",userpassword:"meowheckerps",phoneNumber:["12312332","23123123"]}) ``` ## Entity-relation Model ![](https://i.imgur.com/AHFXrMa.png) --- ![](https://i.imgur.com/JCEbUO0.png) --- ![](https://i.imgur.com/CjSIb6d.png) --- ![](https://i.imgur.com/2upsrbZ.png) ---