0

I have my program that when executed accepts user input. I want to run this as a service on a port on my Linux VM. How can I achieve this?

I would be connecting from my localhost/remote using netcat probably to connect to this listening service.

The programming language I have used is C++

h4xorhead
  • 9
  • 3
  • I am not sure if you really need to register application in [/etc/services](http://linux.about.com/cs/linux101/g/slshetcslshserv.htm). If not, you may just write a script to launch your application, and place it in `/etc/init.d/` directory. Ideally the script would have to answer commands "start" and "stop". But you may ignore it. Don't forget to give executable bit to the file! – Hi-Angel Jul 29 '14 at 07:08
  • 1
    http://stackoverflow.com/questions/13519933/executing-script-on-receiving-incoming-connection-with-xinetd – V H Jul 29 '14 at 09:17

2 Answers2

0

you have to edit the file /etc/services and register your "program" listening on tcp/udpd port ...

donald123
  • 5,638
  • 3
  • 26
  • 23
  • Why? I think he is just have to place a script in the `/etc/init.d` directory, that's all. – Hi-Angel Jul 29 '14 at 06:38
  • init.d starts the "program" in runmode .... to register ports the /etc/services imho must know the ports – donald123 Jul 29 '14 at 06:41
  • Why edit /etc/services? The only reason to look at /etc/services is to insure you are using an open port (or at least one not used by applications that currently run on your host). Whether a service is listed in /etc/services or not does not prevent it from listening on that port. For example, edit /etc/ssh/sshd_config and set the port to something other than 22. Then `ssh -p newport` works fine on the new port without touching /etc/services. – David C. Rankin Jul 29 '14 at 07:39
  • Of course .. sshd_config set the port by config ... don't know if the op write a seperate config script to do this ... – donald123 Jul 29 '14 at 07:42
0

You may want to check out D.J. Bernstein's tcpserver (see http://cr.yp.to/ucspi-tcp/tcpserver.html). Basically, you can simply run your existing program under tcpserver, and tcpserver will handle everything as far as setting up the sockets, listing for incoming connections on whatever port you are using, etc. When an incoming connection arrives on the port that you specify, tcpserver will spawn an instance of your program and pipe incoming info from the client to your program's STDIN, and pipe outgoing info from your program's STDOUT back to the client.

mti2935
  • 11,465
  • 3
  • 29
  • 33