Hey so I am trying to create a WebSocket server, so my client (on a different application) can connect to it. I found a simple WebSocket server example and tried connecting to it and it worked. Though, when I remixed the project (and changed nothing) I couldn’t connect to it. I’ve tried so many different ways to create a WebSocket server that will connect to this client, and if they seem to work, and I remix the project or use the code, it never seems to work on its own.
I thought I’d mention that I’m having some similar problems. I can’t seem to get a websocket server of any kind running. All attempts to send messages to the project url (ie wss://project.glitch.me) result in “WebSocket connection failed”.
// Create WebSocket connection.
const socket = new WebSocket('wss://public-sphere.glitch.me/');
// Connection opened
socket.addEventListener('open', function (event) {
socket.send('Hello Server!');
});
// Listen for messages
socket.addEventListener('message', function (event) {
console.log('Message from server ', event.data);
});
// Listen for messages
socket.addEventListener('error', function (event) {
console.log('Error from server ', event);
});
Hi there! If you add a user agent to your request headers, it should work. We block requests when there is no user agent unless you’re a Glitch subscriber. If you’re a subscriber and still having this issue, let us know the name of the project so we can figure out what’s going on.