By Lucus Xu
I’m trying to run a simple python server on my droplet, with the python script below, and it works fine on my friend’s alicloud server. I guess it was the port I used was not configed correctly, but found out the firewall in ubuntu was not enabled. So i added some new rules to the cloud firewall to open the port 8005(which i intend to ues), but it still doesn’t work. Can anyone tell me how to config this?
# coding:utf-8
import socket
from multiprocessing import Process
def handle_client(client_socket):
request_data = client_socket.recv(1024)
print("request data:", request_data)
response_start_line = "HTTP/1.1 200 OK\r\n"
response_headers = "Server: My server\r\n"
response_body = "<h1>Python HTTP Test</h1>"
response = response_start_line + response_headers + "\r\n" + response_body
client_socket.send(bytes(response, "utf-8"))
client_socket.close()
if __name__ == "__main__":
name=socket.gethostname()
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind((name, 8005))
server_socket.listen(128)
while True:
client_socket, client_address = server_socket.accept()
print("[%s, %s]user connected" % client_address)
handle_client_process = Process(target=handle_client, args=(client_socket,))
handle_client_process.start()
client_socket.close()
and here’s the errorcode: ConnectionRefusedError: [WinError 10061] thx a lot!!!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hello, @VEWOXIC
You can either enable it and use or just use iptables to open the port. Basically it’s totally up to you, but UFW’s syntax is easier to use.
Let me know if you have any questions.
Regards, Alex
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.