Connect via websockets

Is it possible to connect to a websocket server?

Here is a snippet of my server code:

const ws_port = process.env.PORT;
const wss = new WebSocketServer({ port: ws_port });
console.log('listening for connections on %s...', ws_port);

When I deploy this server, I correctly see the log message:

listening for connections on 10000...

Locally, I can connect with

But when I try connecting to my app using websockets on Render
my request times out. Nothing shows up in the logs. I assume the ws request is getting blocked.

It seems like a common use case that should be possible. Is there a way to connect via websockets?


Edit: I notice in the docs (Web Services | Render Docs) it says

Only HTTPS requests (port 443) are accepted.

I’m unclear whether that means only secure traffic is allowed, or if it means other protocols are not supported. For instance, can I use secure websockets? (wss://)

Hi there @Aaron_Wilson,
Yes it is possible I have tried it myself !!
here is a picture of the server receiving messages

here is a picture of a client sending messages


here is the code used for the simple ws server

Sample codes for those who want to try
here is the code for the client

      var conn = new WebSocket('wss://');
      conn.onopen = function(e) {
          console.log("Connection established!");
      setInterval(() => {
        conn.send('Hello server!');
      }, 1000);
      conn.onmessage = function(e) {
      conn.onclose = function(e) {
      conn.onerror = function(e) {

I have also tried and it works like a charm just make sure your then your testing in your localhost you do it in https://localhost/app

code for client (

      var socket = io("", {transports: ['websocket']});
      socket.on('message', function(msg){
        el = document.getElementById('server-time');
        el.innerHTML = 'Message ' + msg;
      setInterval(() => {
      }, 1000);
    }catch (error){

Code for server

Happy coding

Thanks for the detailed response! You helped me get it working.

I was trying to connect using ws://

Your answer helped me discover two things that I needed to fix:

  1. From the client ws:// does not work - you must use wss:// to connect
  2. From the client, do not specify a port. I needed to drop the :10000 and just use ws://

Now it works like a charm. I’d love to see both of these points added to the official documentation.


As a side note, I’m using the free individual tier to prototype my socket service, and I’m noticing that my connections are closed after 5 minutes - even if they are actively sending messages. I’m hoping this is an artificial (and undocumented?) feature of the free tier.

On the plus side, it’s great for exercising my client’s reconnect logic. :roll_eyes:

Hi there,
It is a known bug we have of the free tier, if you bump up to a paid plan you probably won’t experience this - you can always return to free if it continues,


John B

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.