#Hot reload websocket server without dropping clients connection

1 messages · Page 1 of 1 (latest)

pure laurel
#

Hi,

Is there a way to hot reload a TCP server without dropping clients connection?
I have tried the following:

// server.ts
export class Server {
    open = async (socket: Socket) => {
        console.log('changes here') // not reflected if I change this string
    }
}

// index.ts
declare global {
    var socket: TCPSocketListener<undefined>
}

globalThis.socket ??= Bun.listen({
    hostname: 'localhost',
    port: 25565,
    socket: new Server(),
})

// terminal
$ bun --bun --hot run index.ts

And while changes are detected fine, they are not applied... It works fine with --watch, but it also disconnects clients.
I have also tried to add the new Server() to globalThis but nothing changes

Thanks for your help!

uneven frost
#

Bun.listen() is tcp

#

You want Bun.serve()

pure laurel
#

I believe both create a TCP server anyway right? I actually need listen here, Bun.serve() does not work for my use case (minecraft server)

#

but you are right that it is not an actual websocket server, I got confused

#

in any case, my problem is not resolved 😢

pure laurel
#

Any help would be appreciated here! 🙏

mint relic
#

--hot maybe?

pure laurel
# mint relic --hot maybe?

Thanks for the help, I am indeed using --hot (tried with both --watch and --hot): bun --bun --hot run index.ts

#

At this point, I am thinking of filing an issue for this