0

I recently got my own domain, it has hosting and a DNS server. How can I connect to it using the program?

let listener = TcpListener::bind("http:://my_example_domain").await.unwrap();

I use rust programming language, and usually instead of "my example domain", it is "localhost:8080". so can I somehow switch to my domain?

I tried to put the IP address of my DNS server instead of the domain, but the program still displayed an error

2 Answers2

1

To start with, you're mixing up TCP and HTTP. Plain TCP sockets don't deal with HTTP URLs (or any other kind of URL really) – they're only a building block on top of which HTTP and similar protocols could be implemented – so if you're working with raw TCP, the http:// prefix has to go.

Second, bind() is an entirely local matter. It doesn't contact your DNS server, and it doesn't have any way to "pull" connections; it only starts accepting connections that would already arrive at your machine anyway.

This means that you need to manually update your domain to point to the right machine.

Third, most importantly, sockets are never actually bound to a domain, only to an IP address. Even though the TcpListener class might accept a domain name, what actually does is translate that domain to the associated IP address and bind to that address; e.g. when you specify "localhost:80" that just expands to "[::1]:80" plus "127.0.0.1:80".

So the first question is: What IP address does the domain name point to? And does that address belong to the machine you're running the code on?

If the IP address isn't assigned to the machine, then it doesn't make sense to bind a socket to it – the machine would never receive connections to someone else's IP address, so the OS won't even let you do that. In general, the OS won't accept any address that doesn't show up in ipconfig or ip addr, so e.g. if your machine is behind NAT with a private address, it'll only let you bind to its own private address (even though a domain name would point to the public address instead).

Because of this, it's generally rare and not very useful to specify a domain name to bind() even in programming languages that happen to accept it. Instead, specify the IP address manually – or use 0.0.0.0 as a shortcut to mean "all IP addresses". Then, as mentioned already, visit your domain's DNS control panel and make sure it points to your address.

(If it points at your web-host server and you're trying to run the Rust code at home, you can keep them separate by creating a subdomain.)

grawity
  • 501,077
0

Your question is confusing because you seem to be lacking understanding on the different concepts.

A domain is a domain, and can be resolved (= translated) to an IP address (networking address).

A "DNS server" serves domain to IP address resolutions.

When you want to address or connect to your own server, you don't directly connect to the DNS server. You connect to your Domain, which your operating system recognizes as not known yet, and then asks its configured DNS server for an IP resolution, and then transparently connects to that IP address.

When an example talks about http:://my_example_domain or localhost you replace that with your domain name, like example.org.

localhost always resolves to your local machine. Typically, it is used during development/testing and local installations with a web interface.

The first part to connecting via the networking protocols TCP and UDP is the IP address. The second part is the port, that is bound by a single program.

If an example talks about localhost:8080, and you install it on your server, you will likely emit the port :8080 when you access it via HTTP - depending on what the (default) configuration of the webserver and service is.

In

let listener = TcpListener::bind("http:://my_example_domain").await.unwrap();

you would replace my_example_domain with your domain - your fully qualified domain like example.com or customer123.example.com.

Kissaki
  • 773