XML-RPC connection problem - python

I have a simple xml rpc server running on a localhost. The server has the following address:
servAddr = ("localhost", 8080). When I run the client on a different machine I get a connection refused error. However, when i change the line
servAddr = ("localhost", 8080)
to
servAddr = ("myhostname", 8080)
everything works fine...
Why ? And how to know hostname in startup script for machine ?

'localhost' refers to your local machine. It's an alias to 127.0.0.1 ip address. It only works when the server and the client are running on the same machine.
When you try to put the client on an other machine, localhost refer to the machine of the client --> no the machine of the server !
More information about localhost here.

localhost is a relative host name that (usually) always resolves to your local computer. So when you're on a different computer and connecting to "localhost", you'll be attempting to connect to it, rather than your actual XMLRPC server.

Related

I can't connect to pc socket server with mobile socket client python

Hello I tried a simple server and client script on my pc. It was working perfectly but when I tried to connect with pc server with my mobile it is not working I can't connect to pc server with my mobile client
Nothing works I tried changing ip not working I tried changing my laptop internet connection not working I tried using a third party app it says couldn't connect to host and my server script is completely fine
both devices will need to be on the same WLAN or Wifi Network.
you will also need to get your PC's network IP Address (eth0 or your main network card), then you will need your server to listen on ip 0.0.0.0 with the port you want to use.
Have a close look at your firewall and enabled outbound/inbound connnections for the port that you are using.
then you will need to put step 2's ip address as the server ip
then this should work

How to make python server public to other computers in a Linux machine?

I have an ubuntu computer and I want it to act as a server. How do I need to configure the ubuntu computer to be accessible from other computers? Let's say I have this very simple python TCP server:
from socket import socket
with socket() as server:
server.bind(("", 5555))
server.listen(5)
print("[+] Server Listening")
client, addr = server.accept()
print(f"client connected from address {addr}")
How can I make this server public to other computers to connect?
One way you can expose your local service publicly is by using some kind of application like localtunnel or ngrok
Example with ngrok:
ngrok http 5555
Example with localtunnel:
lt --port 5555
These applications will open a tunnel on a random port locally and forward all the connections it gets on the application generated URL to the port you have specified.
Do not use these for production. Not very reliable approach
Well making a server publicly available is something that we need to know more details
about your project. What do you mean about public?? Do you want your server to be publicly available to internet?? Or you just want to use it in your local LAN????

python ZeroRPC heartbeat error on public IP

I run a ZeroRPC server and I can connect successfully with a client to the 127.0.0.1 IP.
However when I use the public IP of the server to the client I get the following error:
zerorpc.exceptions.LostRemote: Lost remote after 10s heartbeat
I have opened the port from the firewall (using ufw on Ubuntu) but still get the same error.
Do you have any ideas what the problem might be?
Thanks!!
What IP address are you binding the server onto? If you want to listen on all interfaces and all addresses, something like tcp://0.0.0.0:4242 should work.

Flask isn't recognising connections from other clients

I have an apache server setup on a Pi, and i'm trying to learn Flask. I set it up so that The 'view' from the index '/' returns "hello world". then i ran my main program. nothing happens from the browser on the PC i'm SSH'ing from,I just get an error saying , but when i used the Pi directly and went to http:localhost:5000/ i got a response.I read about setting Host to '0.0.0.0' but that didnt help. how can i get my Flask to accept all connections? does it make a difference that I have an 'index.html' in '/'?
you need to configure your firewall on your server/workstation to allow connections on port 5000. setting the ip to 0.0.0.0 allows connections to your machine but only if you have the port open. also, you will need to connect via the ip of your machine and not localhost since localhost will only work from the machine where the server is running.

SSH Tunnel for Python MySQLdb connection

I tried creating a SSH tunnel using
ssh -L 3306:localhost:22 <hostip>
Then running my python script to connect via localhost
conn = MySQLdb.connect(host'localhost', port=3306, user='bob', passwd='na', db='test')
However, I receive the following error
(2002, "Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)")
How can I make sure I'm hitting the correct host and not just some problem with the bind?
Try changing "localhost" to "127.0.0.1", it should work as you expect. This behavior is detailed in the manual:
UNIX sockets and named pipes don't
work over a network, so if you specify
a host other than localhost, TCP will
be used, and you can specify an odd
port if you need to (the default port
is 3306):
db=_mysql.connect(host="outhouse", port=3307, passwd="moonpie", db="thangs")
If you really had to, you could
connect to the local host with TCP by
specifying the full host name, or
127.0.0.1.
Does mysqld run on port 22 on the remote? Call me ignorant but I think what you're trying to do is
ssh -n -N -f -L 3306:localhost:3306 remotehost
Then making MySQL connections on local machine will transparently get tunneled over to the target host.
You can't specify localhost as the hostname, as this suggests that MySQLdb should try to use a UNIX socket. Use 127.0.0.1 for the host instead.
If you want to make sure the connection works, you can use the standard mysql client.

Categories