Python Socket Doesn't Work Between Host and VM - python

I am learning python socket programming. Everything works fine if I run locally (both server and client scripts). However, when I moved the server script to a VM (Ubuntu 14.04) and run the client script from the host os (Windows 7) I got this error:
ConnectionRefusedError: [WinError 10061] No connection could be made because the
target machine actively refused it
When I tried running the client inside the VM, it works just fine (except if I use the IP address i.e:192.168.1.6, I have to use it in both scripts). From my search, I found that linux does not activate the firewall by default. What did I do wrong?
Both machines can see each other ( i have set Samba between them, can ping others etc). This is really confusing for me.

Probably this may solve the problem.
You have a bind call in your server code, it looks like sock.bind(('127.0.0.1', 3333)), where 3333 is the server port number. Change the IP address to the empty string, or '0.0.0.0', so it would look like sock.bind(('', 3333)). Then start the client again.
The original bind call binds the server socket only to the loopback interface (lo), which works only within the VM. By binding to the wildcard address ('' or '0.0.0.0') the server will accept connections from any IP address.

Related

Incoming ZeroMQ traffic dropped by server due to NAT?

I have a ZMQ server listening on port 12345 TCP. When another server connects on that port locally or via VM it works fine, but if I try from a remote server that has to go through port forwarding on my Fios firewall it just bombs. The packets are showing up in Wireshark but ZMQ just ignores them. Is there anyway to get past this?
You shouldn't be able to bind more than once to the same port number, either from the same process or another.
ZMQ should give a failure when you issue bind with a port number already in use. Are you checking return codes?

why connection always gets refused?

I am trying to connect machine using the RPyC but it always says that connection refused.
I did on the python shell
import rpyc
rpyc.connect("hostname", port)
but it says connection refused. checked the firewall for the port. firewall allow this port.
Try using the exact same versions of both python and rpyc on client and server !
This means that you are not runnin the server side for rpyc
you need to donwload the source code for rpyc from here
https://github.com/tomerfiliba-org/rpyc/releases
then run:
python bin/rpyc_classic.py
where bin is in the source code folder
Once you have that running, you should be able to run the python code without any issues
I hope it works
default server binds to localhost, but the client needs to have hostname 'None' to do this correctly:
rpyc.connect(None, port)

Heroku, flask, and python sockets?

I have a python script that runs on my computer. It opens a socket and prints anything it receives. This definitely works -- I've managed to connect to it from other computers and send it data.
The problem is that my heroku app fails to connect to the socket.
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((daemon_socket_vars['host'], daemon_socket_vars['port']))
s.send("Hi!")
s.close()
The heroku app fails on the second line after timing out. When I run something identical on either my laptop, or a friend's laptop (while the python script that's acting as the server is running on my laptop in both cases) it works. Does anyone know why heroku would have problems with this? Thanks!
When running on Heroku, your server should bind to port specified in the environment variable PORT (say 7880, just for the sake of this discussion). It is not guaranteed to be 80, 5000, 8000, 8080, or anything else.
To the outside world, however, this will appear as port 80 or port 443. That is, if connecting from outside of Heroku, your client will be connecting to port 80.
One final caveat: when connecting from outside Heroku, your client will go thru the "Heroku Routing Mesh", which among other things does the 80-->something port "translation". The thing is, the routing mesh is an HTTP routing mesh: it will only accept incoming HTTP requests, and will route them (after sometimes altering them, like adding headers etc.) to your dyno.
So you can't just write a plain-sockets app on the Heroku and connect to it directly, you'll have to use HTTP as your transport.

What do I use for HOST to connect to a remote server with mysqldb python?

Things to note in advance:
I am using wampserver 2.2
Ive forwarded port 80
I added a rule to my firewall to accept traffic through port 3306
I have added "Allow from all" in directory of "A file i forget"
My friend can access my phpmyadmin server through his browser
I am quite the novice, so bear with me.
I am trying to get my friend to be able to alter my databases on my phpmyadmin server through
python. I am able to do so on the host machine using "127.0.0.1" as the HOST. My Question is, does he have to use my external ip as the HOST or my external ip/phpmyadmin/ as the HOST? And if using the external ip iscorrect...What could the problem be?
If your phpmyadmin runs on the same machine as mysql-server, 127.0.0.1 is enough (and safer if your mysql server binds to 127.0.0.1, rather than 0.0.0.0) if you use tcp(rather than unix socket).

Connecting to Python XML RPC from the Mac

I wrote an XML RPC server in python and a simple Test Client for it in python. The Server runs on a linux box. I tested it by running the python client on the same linux machine and it works.
I then tried to run the python client on a Mac and i get the following error
socket.error: (61, 'Connection Refused')
I can ping and ssh into the linux machine from the Mac. So i dont think its a configuration or firewall error.
Does anyone have any idea what could be going wrong?
The code for the client is as below:
import xmlrpclib
s = xmlrpclib.ServerProxy('http://143.252.249.141:8000')
print s.GetUsers()
print s.system.listMethods()
"Connection Refused" means the connection was REFUSED - the machine 143.252.249.141 is up, and in the network, but is not accepting connections on port 8000 - it is actively refusing them.
So maybe the server software isn't running on the server? Or is running in another port? Or is bound to a different IP address?

Categories

Resources