Websocket on Heroku

I'm following the chat app tutorial in the async book and I have a question. If I wanted to deploy the chat server to a service like Heroku, what would I use instead of "" on this line:

fn run() -> Result<()> {

I built this server and deployed to Heroku with the following code, and I believe it is working:

let port = std::env::var("PORT").unwrap();
println!("Listening on port {}", port);
task::block_on(accept_loop(format!("{}", port)))

When I check the logs, it appears to be running on that port but I wanted to ask if this was the correct way to code it.

Second, I can't get the client working. For the client app, the tutorial shows:

fn run() -> Result<()> {

but I have no idea what to put in place of that IP address. Since I'm printing the port to the server console, I can get the port number and I can also look up the IP address associated with the Heroku URL but when I tried that I get an error message that says:

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

Does anyone know what the client connection code should look like?

The IP you specify for to listen on specifies which network interface to listen on. You typically have one network interface for localhost, one for each ethernet cable, and one for wifi. Using means listen only on localhost, and means all interfaces.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.