1

I have a Java GRPC endpoint and I want to call it from a RUST client. If I use postman I get the response. Everything is fine.

Postman call

1

When I try to do it from rust, I get the error:

Error: tonic::transport::Error(Transport, hyper::Error(Connect, ConnectError("tcp connect error", Os { code: 111, kind: ConnectionRefused, message: "Connection refused" })))

Code:

use todo::todo_client::TodoClient;
use todo::{CreateTodoRequest};

pub mod todo {
tonic::include_proto!("todo");
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {

let mut client = TodoClient::connect("http://0.0.0.0:50052").await?;

let create_request = tonic::Request::new(CreateTodoRequest {
    username: "username".to_string(),
    password: "password".to_string(),
});

let create_response = client.authenticate(create_request).await?;

println!("{:?}", create_response.into_inner());

Ok(())
}

I tried change the URL to "localhost", with and without http://, didn't work. Im using the same proto file:

syntax = "proto3";

package todo;

message CreateTodoRequest  {
   string username = 1;
   string password = 2;
}

message CreateTodoResponse  {
   int32 expiresIn = 1;
   string accessToken = 2;
   string refreshToken =3;
   string idToken = 4;
}

service Todo {
   rpc authenticate(CreateTodoRequest ) returns (CreateTodoResponse );
}
vimuth
  • 5,064
  • 33
  • 79
  • 116
Marcellgy
  • 11
  • 1
  • Does this answer your question? [Is 0.0.0.0 a valid IP address?](https://stackoverflow.com/questions/3655723/is-0-0-0-0-a-valid-ip-address) – Federico klez Culloca Aug 11 '22 at 10:46
  • (sorry I misread part of your question. It's not a duplicate of that one, but surely using `0.0.0.0` is not helping :) ) – Federico klez Culloca Aug 11 '22 at 10:47
  • 1
    My java server is running on localhost:50052 , tried "localhost:50052", "http://localhost:50052", "http://0.0.0.0:50052", "0.0.0.0:50052, "127.0.0.1:50052", "http://127.0.0.1:50052" none of them worked. from postman I use "localhost:50052" – Marcellgy Aug 11 '22 at 10:50
  • If I use the same URl like in postman "localhost:50052" I got: Error: tonic::transport::Error(Transport, hyper::Error(Connect, "invalid URL, scheme is missing")) – Marcellgy Aug 11 '22 at 10:52
  • What error does using `http://localhost:50052` give? Because the error in the question is because the `0.0.0.0` address is not valid, the one in the above comment is because it's missing `http://`. – Federico klez Culloca Aug 11 '22 at 10:54
  • `http://localhost:50052` -> `Error: tonic::transport::Error(Transport, hyper::Error(Connect, ConnectError("tcp connect error", Os { code: 111, kind: ConnectionRefused, message: "Connection refused" })))` – Marcellgy Aug 11 '22 at 10:55
  • I tried your code with a known-working server (and client) and it works for me. The **only** way that I am able to get connection refused errors is if indeed there's no server listening on that port. Can you show that `ss --tcp --listening --process | grep 50052` reports a process? What do you get from `telnet 0.0.0.0 50052`? The scheme is, I think, a red-herring, I tend to use `grpc://` with gRPC but I can connect even I use my dog's name as the scheme (`freddie://0.0.0.0:50052`). – DazWilkin Aug 11 '22 at 17:02
  • The only other variable is whether your server and Postman are using TLS. I assume not. – DazWilkin Aug 11 '22 at 17:03
  • Maybe postman is connecting to "localhost" via IPv6? Can you use `ss -nlp` or `netstat` or something (what OS are you on?) to check where the server is listening exactly? Can you use `wireshark` on the `lo`/`localhost` connection to compare the connection attempts? – maxy Aug 12 '22 at 08:30

0 Answers0