Run python server on VPS - python

I create a simple python server:
import socket
server=socket.socket()
server.bind(("0.0.0.0",8820))
server.listen(1)
(client_socket,client_address)=server.accept()
client_name=client_socket.recv(1024)
client_socket.send("Hello "+client_name)
client_socket.close()
server.close()
when I run this script in a VPS I cannot connect to this server
why?
(I get the IP address of the server( with ifconfig command on bash console) and when I run a client script that connect to this address it doesn't connect)

Try to bind the socket server to the vps public IP address and try to avoid ports bellow 10,000 I think most of firewalls prevent incoming connections through ports under 10,000.

Related

How to set different IP for client and server running on same machine?

I used socket module and localhost IP address 127.0.0.1 and both client and server are under same IP (codes written in python and socket modules are imported)
How I use different IP address to server and client if you know please let me know it’s very important

Run DNS server on own ip

I'm implementing a simple DNS server, which I want to run on my pc. But, as far as I understand the combination of my IP and port 53 (standard DNS server port) is already occupied.
This is how I tried to open socket:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('', 53))
This is an error message I get:
socket.error: [Errno 98] Address already in use
But, when I use 127.0.0.1 as IP address when creating a socket, everything works fine and I'm able to get requests.
This is what have tried so far (in Linux terminal I tried to kill the socket):
fuser -k -n udp 53
But it didn't work. So how can I run DNS server on my own IP address?

Python http.server on port 8000 works while xmlrpc.server on port 8000 refuses connection

I am trying to figure out why
python -m http.server 8000
works, while
python rpc_server.py 8000
refuses a connection from remote hosts. My rpc_server.py code is taken verbatim from: https://docs.python.org/3/library/xmlrpc.server.html
When I make a GET request to the http.server, everything works fine, both locally and remotely (router is correctly forwarding requests). Similarly, when I ping the rpc_server from the same machine (localhost), I get a response. However, when I ping the rpc_server from another machine (remote host), I get 'connection refused'. Using tcpdump, I can see that when I submit a SYN request the response is always RST. Why is the SimpleXMLRPCServer sending a reset signal to all remote host requests but not local host requests? (I have tried sending the remote host request using both POSTMAN in Chrome and rpc_client.py [taken from the same tutorial above]).

Connecting to Openshift Python socket server via Adobe Air client

Currently i have work on Python socket server on Openshift. Managed to get it listen to port (15000) and tested on local with telnet seems working fine.
However, i unable to connect to the socket server other than local ( either telnet to the socket server or using Adobe Air xmlsocket )
when i do a netstat on the server, i got following result:
netstat -tan | grep $OPENSHIFT_PYTHON_IP | grep $OPENSHIFT_PYTHON_PORT | grep ESTABLISHED
/proc/net/tcp: Permission denied
not sure whether i missed anything on the configuration on Openshift.
Btw, how can i get the IP of my server? if i use OPENSHIFT_PYTHON_IP the ip is only for local right?
Your websocket server needs to listen on port 8080, and you need to access it at ws://app-domain.rhcloud.com:8000

TCP-IP Communication via Python and an open port of a SSH connection

This is a newbie question for TCP-based communication in Python. I am trying to establish a TCP-based communication between two *NIX systems via an SSH tunnel and the Python socket module. I have used the two first examples "echo server" and "echo client" from this Python MOTW website: http://www.doughellmann.com/PyMOTW/socket/tcp.html.
The communication worked fine on the same *NIX system (HOST1) but failed over the ssh tunnel.
I logged into the second *NIX system with ssh -L 10000:HOST2:10000 USERNAME#HOST2. Then I played around and tried to establish the communication in the same manner by starting the python script for the server on HOST2 and the script for the client on HOST1. This I got on stderr:
python test_socket_client.py
connecting to localhost port 10000
Traceback (most recent call last):
File "test_socket_client.py", line 10, in <module>
sock.connect(server_address)
File "<string>", line 1, in connect
socket.error: [Errno 111] Connection refused
When I started server and client vice versa on HOST1 and HOST2, respectively, I got the same message.
What am I doing wrong?
Your server binds its socket to localhost:10000 -- which means it listens to connections from the loopback interface only. The SSH command line instructs SSH to tunnel local connections to port 10000 to connections to HOST2:10000. Your client Python program connects to localhost:10000, and the remote end of the SSH link then tries to connect to HOST2:10000. Even though that's the same port and the same machine as your socket is bound to, it's a different interface, to which your socket is not listening.
Change the SSH command line to ssh -L 10000:localhost:10000 USERNAME#HOST2, or bind your server's listening socket to all interfaces: server_address = ('', 10000). The empty string serves as INADDR_ANY.
Of course, what Gary van der Merwe said is true: SSH would need to be running at the time you run your client Python program on HOST1.
I would check that your server is listening on the server host, and that the ssh client is listening on the client host. You can run netstat -tnlp to check this.
Are you sure that your ssh client is still open when you are running your client. You either need to run shh in one terminal, and your client in another, or run ssh -Nf which causes ssh to go to the background after it has authenticated.

Categories

Resources