I am attempting to run a python script on a localhost server in order to interact with this script from other terminal windows.
I know there is no fault in the python script as this exact method of connection works on a different machine.
First, I run the following in Terminal Window 1: python ./myserver.py localhost 8080 - my script gives me a message saying that the server script has successfully started.
Second, using Terminal Window 2 I attempt to connect to this localhost via Telnet using the following: telnet localhost 8080 - this is where my error lies. Immediately after I enter the command I receive the following message,
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
How can I fix or at least troubleshoot this problem?
Thanks to VIPIN KUMAR for this suggestion.
I needed to restart the xinetd service as the telnet service was not running correctly.
Related
I am using rpyc to create a Service (server). I was able to do this. Now I'm I would like to run it and connect to it using my client.
I run the server
python3 myserver.py
This runs fine. Then I run the client
python3 myclient.py
The problem is I get an error:
ConnectionRefusedError: [Errno 61] Connection refused
When I run myserver.py from Anaconda Spyder, them my client works fine, but when I run my server from the shell or command prompt, it says connection refused. Is there a specific way I need to run a rpyc server in order to connect to it?
First, check your firewall - is it open for RPyC server port
Also make sure your server uses for binding address 0.0.0.0 and not localhost (127.0.0.1)
Very important to ensure that both server and client use the same Python and RPyC versions
I am new to python socket programming and was following a tutorial building a chat-app, using kivy and sockets. I am running my server on my main PC and I was trying to connect from my laptop to this Server, but it doesn't work (Both my PC and laptop are connected via Ethernet cable). When I run the client.py on the PC that I host my Server on, everything works fine.
I tried running the Server on my 0.0.0.0 address and then connecting from my laptop to the IP address that appears on my Server PC if I type in "ipconfig" (192.168.2.x) but it didn't work. I also tried running the server just on the Ethernet-Adapter IP that appears when I type in "ipconfig" (so 192.168.2.x) but this doesn't work neither.
Lastly I have tried defining my Server IP by using the built in socket function: socket.gethostbyname(socket.gethostname()) (weirdly when I run this, my Server runs on my VMware Network Adapter (192.168.66.x) instead of my Ethernet-Adapter). But this too didn't work :(
The client.py code on my laptop always returns this error:
connection error: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Would appreciate any help :)
edit: Could this have something to do with the firewall on my PC blocking connections or something?
Found the Problem! Today it actually worked by disabling my host PCs Windows Defender internal Firewall and the running the Server on 0.0.0.0, which is very weird because yesterday it didn't work...
I have very simple script that establishes connection to another host and then creates the tunnel through which another application connects to SQL Server.
self.dicSession['server'] = sshtunnel.SSHTunnelForwarder(
('remote_host', 22),
ssh_username="username",
ssh_password="password",
ssh_private_key="key_rsa",
remote_bind_address=('remote_host', 53425),
local_bind_address=('localhost', 1433),
)
self.dicSession['server'].start()
It works fine. However the command to stop the server. When the connection is established I am using tunnel (between 53425 port of remote host and 1433 port of localhost) to connect to a SQL Server that operate on the remote host. Up to this point everything works fine. It seems however that stopping the SSH connection with command
self.dicSession['server'].stop()
does not work properly. Despite the command to stop the connection I am still able to execute SQL statement and get results. Moreover when I execute the SQL query after the command
self.dicSession['server'].stop()
the app - which us build with usage of PyQT5 - freezes. To be honest I have not tried to run the script without GUI but I will need the GUI as the app is not only for me but for other people who are not familiar with CLI.
This happens because your client is still open.
It will allow you to stop server, once you closed your client.
Situation
I wrote a simple program in python. It's a simple socket chatting program. In my program, the client just connect to an address (ip, port) and send a message, while at this time the server is ready and receives the message and prints it. I can assure the program is correct, since I tried on my computer.
I have a VM instance on Google Cloud Platform, which I can operate through ssh, a simple way provided by google cloud. I can make sure the server is working.
Problem
I start a simple tcp server, python program on my google cloud server. Then I start my client program on my computer. But I get this error:
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
or equivalently in Chinese:
ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
How do I solve this problem and connect to my google cloud server?
I guess maybe the firewall refused my computer's connection, but have no idea how to solve it.
This error means that your program is not listening on 0.0.0.0 port XYZ.
Check to see if your program is instead listening on localhost. If it is change to 0.0.0.0 which means all available networks. localhost means do not listen on any network interfaces and only accept connections from inside the computer.
Then double check the port number.
To see if you have something listening run this command (Linux): netstat -at
Look for a line with your port XYZ.
When you start your program, make sure that it does not error when creating the listener. If you are trying to use a port number below 1024, you will need to lauch the program with root privileges.
The TCP connection is being refused because the GCP Firewall is indeed blocking it. Therefore, you must create a firewall rule that opens the TCP port for Ingress connections.
By navigating to Firewall rules in the VPC network section of the GCP Console, you can create firewall rules or update existing ones.
One approach is to tag your GCE instance, and when creating the firewall rule, set the target to be this tag, and as for 'Source filters', the IP of the machine you're attempting to establish the connection from, or simply allow all IPs to connect with 0.0.0.0/0 as the source. Remember to specify the TCP port that needs to be opened.
this this probably a very simple question, but I haven't been able to find an answer anywhere. On the online articles about it, they didn't show the exact process to share a directory using SimpleHTTPServer. I've run the command successfully and have the server running, but I can only access it on the machine that started it.
192.168.1.2:8000
I've tried it on a Windows machine and iPad (although that doesn't really make a difference) on the local network. To access it, I've been using my local IP address, which I found by running ifconfig | grep inet, which returns (among other matches):
inet 192.168.1.2 netmask 255.255.255.0 broadcast 192.168.1.255
And after searching a bit online, I found: https://github.com/shbhrsaha/instant-sharing/blob/master/share.py.
There's function which supposedly gives you a handy url to share with your friends, but I tried running locally, and all I got was "localhost.localdomain", which obviously returns 127.0.0.1
How can I make this work?
When you start SimpleHTTPServer it tells which IP addresses it is listening to:
python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
Address 0.0.0.0 means it listening to all available IP addresses. Thus in this case you should simply reach the server by going http://192.168.1.two:8000
If it doesn't work then it is most likely a network issue. You can test this out with telnet command (both Windows and UNIX available): telnet will open a TCP/IP connection on a certain IP and certain port.
E.g. on UNIX you can do:
telnet 192.168.1.2 8000
If you get:
telnet 192.162.1.2 8000
Trying 192.162.1.2...
telnet: connect to address 192.162.1.2: Connection refused
telnet: Unable to connect to remote host
... it means SimpleHTTPServer is running.
If it waits for very long time it means your router/firewall is blocking the connection.
If you get a reply:
telnet localhost 8000
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
... browser should work as well. You can quit telnet by just keep hitting the enter (the SimpleHTTPServer will close the connection).
In Ubuntu
I had the same problem, then I narrowed it down to be a firewall problem.
First, check if your firewall is active.
sudo ufw status
If it is active by default it blocks all incoming connections from anywhere.
You can check whether you have granted access to your running port. The following command will list down all the available rules. if your port is not there with access given to other ports then you need to grant access.
sudo ufw status numbered
[This is what the issue] Now grant access on the port for desired ip addresses/ all. I allowed all incoming connections to the port 8000 on all ip adress by following command.
sudo ufw allow from any to any port 8000 proto udp
Initially, I thought this should be tcp instead of udp but worked with udp only. Something to dig up later.
The server was running, and we could access it, but only on the server's machine.
There was something blocking the connection, and that was The Firewall.
We configured The Firewall and it worked fine, my other device could get access.