Make sure that Node.js and npm are installed on your system.
Navigate to the project directory: cd cs361microservice
npm install
npm start
const WebSocket = require('ws')
const port = 8080
// Set up server
const wss = new WebSocket.Server({ port: port })
// Wire up some logic for the connection event (when a client connects)
wss.on('connection', function connection(ws) {
// Wire up logic for the message event (when a client sends something)
console.log('Server connected')
const diceSize = 6
// Send a message
ws.send(JSON.stringify({dice: diceSize}))
// Receive Incoming message
ws.on('message', function incoming(message) {
console.log('Dice rolled: %s', message)
})
})
All done!
![Screen Shot 2024-02-26 at 4 30 59 PM](https://private-user-images.githubusercontent.com/134333201/307996688-e8095bdd-bd28-4259-87f2-626dae0d07c5.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1NDc3MjcsIm5iZiI6MTczOTU0NzQyNywicGF0aCI6Ii8xMzQzMzMyMDEvMzA3OTk2Njg4LWU4MDk1YmRkLWJkMjgtNDI1OS04N2YyLTYyNmRhZTBkMDdjNS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE0JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxNFQxNTM3MDdaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT02NjJiNTkxZDA1ZWZiYjczZDU3NmNkNWJmYzY4ODlmODQ2ZWY5NGE2Mjc5ZDg2OTJkNWZhYzU3ZDU5NWIyOGQ1JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.1F3EHI1UNZwTzKNzG_iJqctrL6zvSa1hamwikhKKAac)