FAC-11 / FACgame

a lethal game!
https://gunboat-diplomacy.herokuapp.com
10 stars 2 forks source link

Web sockets #14

Closed rebecacalvoquintero closed 7 years ago

njsfield commented 7 years ago

Hey, wanted to share some advice on learning websockets as I understand you guys will be using them in your project?

I learnt them via socket.io (for a project me and jsms90 were involved in after we completed fac), followed a tutorial directly on socket.io's site was quite short. The library is fast to learn and set up (it hides a lot of complexity with sockets, and like many other socket libraries the api is very similar). Be aware that with this route you won't gain a deep understanding of the underlying technology, there are a lot of articles online that go further in detail that I'd encourage you to read at a later point!

If you want to integrate sockets quickly and are strapped for time, my advice would be to split into pairs, follow the tutorial on socket.ios site, make a basic app that allows communication between browser/server.

Hope that helps

https://socket.io/get-started/

P.s To quickly see that everything's working I'd encourage adding console.log statements in each event listener on server side & client side (during development)!

njsfield commented 7 years ago

The chat example tutorial on the site demonstrates using express on the server, and uses jQuery for DOM manipulation on the front end... you should be able to substitute these with vanilla implementations;

// server (no express)

var router = (req, res) => {
  if (req.method == 'get') {
    // req.write etc etc
  }
}
var http = require('http').Server(router);
var io = require('socket.io')(http);

// etc
// browser (no jQuery)

var socket = io();
var myForm = document.getElementById('myform')
var myInput = document.getElementById('myinput')

myForm.addEventListener('submit', (e) => {
  socket.emit('chat message', myInput.value);
})

// etc
rebecacalvoquintero commented 7 years ago

OMG! thanks so so much!! this is super helpful! We have just finished watching the tutotial and now we are about to start working with the sockets. We may need you at some point :) @njsfield @polyccon

njsfield commented 7 years ago

No prob- happy to help. If you need any extra support PM me and will do what I can :)