0
import socket
ms=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host="192.168.0.159"
port=80
ms.bind((host, port))
ms.listen(5)

while True: 
  conn,addr=ms.accept()
  data=conn.recv(1000)
  if not data:
      break

  print (data)
  print ("Got a request!\n")

conn.close()
ms.close()
  • You will most likely find that port 80 is being used by another process. You should check if any other programs have bound to port 80. – Vincent P Oct 16 '18 at 5:35
1

You cannot bind to ports below 1024 without the CAP_NET_BIND_SERVICE capability. The root user has it.

Or, you can assign it to an executable with

$ sudo setcap 'cap_net_bind_service=+ep' /path/to/program

But, caveat, the latter does not work for scripts. You had to add the capability to the interpreter itself, which is a huge security hole. Don't do that.

-1

Perhaps using flask or websockets to expect data on port 80 (if it is not in use) may be a better option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.