0

Im trying to build a python application that will be run on a specific port so that when i try to connect on that port the python application will be run.

Im guessing i have to do that with socket library but im not very sure about that.

asked Oct 19, 2017 at 23:40
5
  • That's not how it works. You have to run your program first, and have it start listening to a port. You can't tell the OS "listen to this port, then run this program to handle any connections to it". Commented Oct 19, 2017 at 23:44
  • that could work too but how do i do that ? Commented Oct 19, 2017 at 23:49
  • Python makes it pretty easy. Take a look here: docs.python.org/2/howto/sockets.html Commented Oct 19, 2017 at 23:54
  • Even easier if you want to use HTTP: docs.python.org/2/library/simplehttpserver.html Commented Oct 19, 2017 at 23:55
  • @Blorgbeard You can do exactly that with xinetd and similar super-servers. Commented Oct 20, 2017 at 0:10

1 Answer 1

1

On Linux you can do this with xinetd. You edit /etc/services to give a name to your port, then add a line to /etc/xinetd.conf to run your server when someone connects to that service. The TCP connection will be provide to the Python script as its standard input and output.

answered Oct 20, 2017 at 0:13
Sign up to request clarification or add additional context in comments.

2 Comments

yeah im actually using linux on virtualbox so i think this could help me THANKS
Hey, that's neat!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.