用户连接时运行命令?
当用户尝试连接到该端口时,是否可以侦听端口并运行命令?理想的应用程序是服务器只应在有人实际使用时运行。 Windows 或 Linux 解决方案均有效。
Is it possible to listen on a port and run a command when a user attempts to connect to that port? Ideal application is for a server that should only be run when someone is actually using it. Windows or Linux solutions work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
linux/unix:
man nc
你可能感兴趣的一些选项
我认为 nc 在 windows 平台下也可用。
linux/unix:
man nc
some options that you may be interested
i think nc is also available under windows platform.
一种解决方案是通过 inetd 或 xinetd,指定端口号和要运行的程序(可能是 shell 脚本)。
One solution could be via inetd or xinetd, specify the port number and a program to run, for you probably a shell script.
我注意到问题的确切范围是什么,但如果绑定到编程级别,您可以以这样的方式编写服务器:当没有人使用它时,除了侦听部分之外,不会分配任何资源。我将其称为延迟初始化。当有人连接时,只需初始化程序的整个逻辑即可。当所有连接都消失后,取消初始化所有内容。
I am note sure what is the exact scope of a question but if bound to the programming-level, you could write your server in a way that when nobody is using it, no resources apart from the listening part are allocated. I would call it lazy initialization. When someone connects simply initialize the whole logic of your program. When all connections are gone, deinitialize everything.