0 Replies - 624 Views - Last Post: 02 November 2015 - 06:17 PM

#1 apaddobs   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 50
  • Joined: 16-May 12

Perl Socket Server Daemon problem

Posted 02 November 2015 - 06:17 PM

sub start {
    my $self = shift;
    my $server = $self->{SOCKET};
    my $client;
    while ($client = $server->accept())
       my $pid;
       while (not defined ($pid = fork())) {
         sleep 5;
       if ($pid) {
           close $client;        # Only meaningful in the client
       } else {
            my $socket = new socket_handle ($client);
            $socket->handle_request ();

I have the above code on the server side that accepts requests from different clients, forks a process for each connection and the requests on a socket are handled via the socket_handle class.

The client opens a connection with a server , sends a file, does some processing, sends another file and so on and so forth.

So where should the "exit" (for the forked process come in). Here's what I am thinking. The client should send some kind of a "quit" (that he's no longer interested in any more activity), and upon receiving such a quit request, the socket_handle class will simply close the socket. Should an exit, therefore, be placed in that quit function?

Right now, the server receives one file and then the client/server just hang.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1