HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Perl socket-daemon example
Operating System - HP-UX
1834149
Members
4002
Online
110064
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2003 05:33 AM
08-22-2003 05:33 AM
Hi!
I'm trying to make a small client-server /using INET-socket/ example on Perl.
Here it is:
#=======================
# Server
#=======================
use IO::Socket;
my $sock = new IO::Socket::INET (
LocalAddr => 'servername.com',
LocalPort => '7777',
Proto => 'tcp',
Listen => 1,
Reuse => 1,
);
die "Could not create socket: $!\n" unless $sock;
my $new_sock = $sock->accept();
while(defined($Line = <$new_sock>)) {
print $Line;
}
close($sock);
#=============================================# Client
#=============================================
use IO::Socket;
my $sock = new IO::Socket::INET (
PeerAddr => 'servername.com',
PeerPort => '7777',
Proto => 'tcp',
);
die "Could not create socket: $!\n" unless $sock;
print $sock "Hi there!\n";
$sock->send("Hi again!\n");
close($sock);
It is working! Now I want to do the following:
1. To make this server to work like a daemon.
I've tried with:
use Proc::Daemon;
Proc::Daemon::Init();
This was working like daemon , but was damaging socket-part.
2. To make this server to "fork" child process,which will execute row
"print $Line" itself and died after that.
Main proccess must remain live after this
action.
Is anywhere a suitable modules and simple code for doing this?
Thank's in advance!A points-gift will be done! Stan
I'm trying to make a small client-server /using INET-socket/ example on Perl.
Here it is:
#=======================
# Server
#=======================
use IO::Socket;
my $sock = new IO::Socket::INET (
LocalAddr => 'servername.com',
LocalPort => '7777',
Proto => 'tcp',
Listen => 1,
Reuse => 1,
);
die "Could not create socket: $!\n" unless $sock;
my $new_sock = $sock->accept();
while(defined($Line = <$new_sock>)) {
print $Line;
}
close($sock);
#=============================================# Client
#=============================================
use IO::Socket;
my $sock = new IO::Socket::INET (
PeerAddr => 'servername.com',
PeerPort => '7777',
Proto => 'tcp',
);
die "Could not create socket: $!\n" unless $sock;
print $sock "Hi there!\n";
$sock->send("Hi again!\n");
close($sock);
It is working! Now I want to do the following:
1. To make this server to work like a daemon.
I've tried with:
use Proc::Daemon;
Proc::Daemon::Init();
This was working like daemon , but was damaging socket-part.
2. To make this server to "fork" child process,which will execute row
"print $Line" itself and died after that.
Main proccess must remain live after this
action.
Is anywhere a suitable modules and simple code for doing this?
Thank's in advance!A points-gift will be done! Stan
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2003 06:02 AM
08-22-2003 06:02 AM
Solution
Here's a close example of something I did for a SysAdmin article to setup multi-platform semaphores using Perl sockets.
The essential steps to daemonizing a process are:
1) fork() -- parent generally just exits the child does the work.
2) setsid() - detaches controlling terminal
3) chdir("/") - so that no filesystems are busy; you don't want to make it difficult for admins to umount a filesystem.
4) setup the signal handlers (e.g. ignore SIGINT, SIGHUP, possibly put in a handler to shutdown when SIGTERM is received.
All of this is illustrated in the attachment plus setting up bidirectional sockets.
The is server.pl.
The essential steps to daemonizing a process are:
1) fork() -- parent generally just exits the child does the work.
2) setsid() - detaches controlling terminal
3) chdir("/") - so that no filesystems are busy; you don't want to make it difficult for admins to umount a filesystem.
4) setup the signal handlers (e.g. ignore SIGINT, SIGHUP, possibly put in a handler to shutdown when SIGTERM is received.
All of this is illustrated in the attachment plus setting up bidirectional sockets.
The is server.pl.
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2003 06:03 AM
08-22-2003 06:03 AM
Re: Perl socket-daemon example
Here's the client piece that talks to the server using sockets.
This is client.pl.
This is client.pl.
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2003 06:27 AM
08-22-2003 06:27 AM
Re: Perl socket-daemon example
Thanks, Mr. Stephenson!
I must look over your scripts in details.
It seems you are an experienced developer
on Perl. I thing I know the main principles, used in "daemonization" of program. And I
have seen it in module: Daemon.pm.
But when I'm trying to apply this
module /look at my 1. above/, I'm doing
my program to work like daemon, but
the server is stopping to receive messages
for client. May I ask you kindly to
look over this module? What is the problem?
I'm attaching it.
Thank you very much, Stan
I must look over your scripts in details.
It seems you are an experienced developer
on Perl. I thing I know the main principles, used in "daemonization" of program. And I
have seen it in module: Daemon.pm.
But when I'm trying to apply this
module /look at my 1. above/, I'm doing
my program to work like daemon, but
the server is stopping to receive messages
for client. May I ask you kindly to
look over this module? What is the problem?
I'm attaching it.
Thank you very much, Stan
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP