2020-06-23 17:07:01

hello all, i want to get clarity.
which is best to use. say i will run my server on my computer and another copy of server in a windows vps. then i should use host='localhost' or host=socket.gethostbyname(socket.gethostname()) or host=socket.gethostname().
what should i use. i dont want to change server again and again each time i change my vps. so what is best to use.

if you like this post, please thum it up!
if you like to see my projects, feel free to check out my github
if you want to contact me, you can do here by skype. or you can follow me on twitter: @bhanuponguru
discord: bhanu#7882

2020-06-23 17:39:25

Read the host from a variable. Then just change the variable. You want to use localhost when you're reading from the local machine, otherwise it might decide to send packets to the router only to send them back to your machine.

You'll eventually register a domain name and just set the variable to that.  But if it's in a variable there shouldn't be any problem if the VPS moves or whatever. They're just strings.

My Blog
Twitter: @ajhicks1992

2020-06-24 07:17:05 (edited by bhanuponguru 2020-06-24 07:17:34)

but say if clients wants to connect from another computer then can i set the server ip to localhost and give my clients the vps IP?

if you like this post, please thum it up!
if you like to see my projects, feel free to check out my github
if you want to contact me, you can do here by skype. or you can follow me on twitter: @bhanuponguru
discord: bhanu#7882

2020-06-24 09:35:57

it depends what you're trying to achieve. the server can be localhost if you're not trying to refer to the client's computer. You need to read up on some network principles.

ReferenceError: Signature is not defined.

2020-06-24 11:29:58

oh. what i am asking is, say i have a windows vps with IP=105.0.1.0 and if i make the socket server in it and set IP adress as localhost and i program the clients as IP=105.0.1.0 and will it work?

if you like this post, please thum it up!
if you like to see my projects, feel free to check out my github
if you want to contact me, you can do here by skype. or you can follow me on twitter: @bhanuponguru
discord: bhanu#7882

2020-06-24 12:33:14

yes it should

best regards
never give up on what ever you are doing.

2020-06-24 16:15:29

No, it won't. Set the hostname of the server to 0.0.0.0. This means listen on all interfaces.

Then listen to me when I tell you that this is complicated, and that you need to learn stuff, and go learn stuff properly instead of hoping that if you bang on it for long enough and start enough threads on a site where less than 10 of us know networking you'll get something that works.  What you're asking and why I'm saying what I'm saying is covered in literally any basic networking resource in the history of the internet, and if you did your own reading since the last time you asked how networking worked you wouldn't have needed this thread.

My Blog
Twitter: @ajhicks1992

2020-06-25 09:37:52

bro i know how networking works but my confission is, can we say if we have our server.py in the vps wich has IP adress of 123.4.5.6. and if i code the server like s.bind(('localhost', 12345)) and i am runnig the client in another computer and i set it like s.connect((123.4.5.6, 12345)) and is it going to connect to my server.py which is on 123.4.5.6? that is my question post#7

if you like this post, please thum it up!
if you like to see my projects, feel free to check out my github
if you want to contact me, you can do here by skype. or you can follow me on twitter: @bhanuponguru
discord: bhanu#7882

2020-06-25 09:58:07

why would you need localhost? if you put your server.py on your vps, you should use the ip address of your vps. not localhost...

best regards
never give up on what ever you are doing.

2020-06-25 18:07:08

@8, your questions suggest otherwise.
Also, I'm telling you this because I don't think you intended to sound like that, but the use of the word "bro" in your post came off as pretty disrespectful, at least on my end. Something you should keep in mind

2020-06-26 06:27:57

ok. i will use the word friends instead of bro. OK?

if you like this post, please thum it up!
if you like to see my projects, feel free to check out my github
if you want to contact me, you can do here by skype. or you can follow me on twitter: @bhanuponguru
discord: bhanu#7882

2020-06-26 06:29:48

@9 can i use socket.gethostbyname(socket.gethostname())? i think it returns IP of my own vps

if you like this post, please thum it up!
if you like to see my projects, feel free to check out my github
if you want to contact me, you can do here by skype. or you can follow me on twitter: @bhanuponguru
discord: bhanu#7882

2020-06-26 11:22:04

@8 If you s.bind(('localhost', 12345)) the server will only listen for connections on its loopback interface (only for internal machine use).
If you need to allow external clients to connect then you will want the s.bind(('', 12345)) version as it means to listen for connections on all IP addresses the server has available.

2020-06-26 11:28:01

oh ok. but can i use socket.gethostbyname(socket.gethostname())? this will return the IP adress of the computer by which i run the server. so if i change my vps also it will automaticly detect my vps IP and i can use that IP with the client program. hope you understand and am i right?

if you like this post, please thum it up!
if you like to see my projects, feel free to check out my github
if you want to contact me, you can do here by skype. or you can follow me on twitter: @bhanuponguru
discord: bhanu#7882

2020-06-26 11:46:12

@13 No because if you run this code you'll get the IP address of the client. You will need to embed the servers' IP address on the code or get it somewhere if it will change frequently.
Put it another way, you can't get the IP address of the VPS if you don't know even where it is.