Hi there, long time reader, first time poster
I’m building a multiplayer game using Node.js, Express, socket.io
and p5.js. Please bear with me if I am adding irrelevant info to my queries and let me know if I am leaving out any useful info
Here is a link to the current version: https://fuzzy-troubled-pheasant.glitch.me/
(Remix link on the page, limiting number of links as I am new :))
I can get the multiple clients to communicate with the server and draw multiple users on my p5 canvas, but I kept getting 400 error.
I think this means that I have not set up the client side correctly, but the program was still working as I expected it too so it must be communicating somehow…?
The “400” errors were resolved by also adding ‘polling’ to transports:
transports: [‘websocket’,‘polling’],
Now I am getting “200” status codes instead, like on Socket.IO
tutorials. Is this because it was always communicating using ‘polling’ and now I have “okayed” that type of communication?
But now, whenever a user connects two connections are made. Ciccen (I’ve gone with old-timey spelling for types of birds, not sure why) is the active user and ‘Them’ is the placeholder username I am setting for all connections:
I thought maybe Them was the result of an open browser window, but that second connection alsways disconnects at the same time as the active user.
My questions are:
- Can you see why two connections are being created?
- How do I include socket.io-client correctly?
I have included socket.io-client in my package.json file but am not sure if I also need to call it in my module script.js. I have tried using the ES6 format as described on Socket.IO
site (have commented out this line in the linked version so the app works):
import { io } from “socket.io-client”;
But then I get the following error:
Uncaught TypeError: Error resolving module specifier “socket.io-client”. Relative module specifiers must start with “./”, “…/” or “/”.
And if I change it to:
import { io } from “./socket.io-client”;
Then I get this error:
Loading module from “
https://fuzzy-troubled-pheasant.glitch.me/socket.io-client
” was blocked because of a disallowed MIME type (“text/html”).
I have been searching for an answer through what feels like the entirety of this forum and stack overflow and I am sure the answer is out there but I am just unable to understand it… Please let me know if my issue is just plain ignorance regarding a certain topic (MIME types or something), I am trying to learn but get overwhelmed with what to focus on Very grateful for your time spent reading all this and for any help