No description
This repository has been archived on 2026-08-22. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
  • Perl 90.1%
  • Raku 9.9%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2016-06-02 21:11:46 +02:00
lib/Mojo/Server remove setuidgid as its removed in version 6.10 2016-04-14 16:30:25 +02:00
t use 0.0.0.0 instead of localhost in case thats that not configured 2016-06-02 21:11:46 +02:00
.gitignore Init repo 2013-12-06 15:39:34 +01:00
.ship.conf Released version 0.04 2015-01-02 12:53:29 +01:00
Changes Released version 0.05 2015-01-03 10:32:22 +01:00
cpanfile Released version 0.05 2015-01-03 10:32:22 +01:00
Makefile.PL Released version 0.05 2015-01-03 10:32:22 +01:00
MANIFEST.SKIP Released version 0.03 2014-06-13 11:44:51 +02:00
README Released version 0.05 2015-01-03 10:32:22 +01:00
README.pod Add Mojo::Server::TCP 2013-12-06 15:39:48 +01:00

NAME
    Mojo::Server::TCP - Generic TCP server

VERSION
    0.05

SYNOPSIS
      use Mojo::Server::TCP;
      my $echo = Mojo::Server::TCP->new(listen => ['tcp//*:9000']);

      $echo->on(read => sub {
        my($echo, $id, $bytes, $stream) = @_;
        $stream->write($bytes);
      });

      $echo->start;

DESCRIPTION
    Mojo::Server::TCP is a generic TCP server based on the logic of the
    Mojo::Server::Daemon.

EVENTS
  connect
      $self->on(connect => sub { my($self, $id) = @_ });

    Emitted safely when a new client connects to the server. $id is a unique
    string used to identify the connection.

  close
      $self->on(close => sub { my($self, $id) = @_ });

    Emitted safely if the stream gets closed. $id is a unique string used to
    identify the connection.

  error
      $self->on(error => sub { my($self, $id, $str) = @_ });

    $id is a unique string used to identify the connection and $err holds
    the error message.

  read
      $self->on(read => sub { my($self, $id, $bytes, $stream) = @_ });

    Emitted safely if new data arrives on the stream. $id is a unique string
    used to identify the connection. $bytes holds the incoming data and
    $stream is a Mojo::IOLoop::Stream object you can use to respond back to
    the client.

    The $stream object can also be retrived in your code using this code:

      $stream = $self->ioloop->stream($id);

    It is much safer to avoid memory leaks to pass $id around instead of the
    $stream object.

  timeout
      $self->on(timeout => sub { my($self, $id) = @_ });

    Emitted safely if the stream has been inactive for too long and will get
    closed automatically. $id is a unique string used to identify the
    connection.

ATTRIBUTES
  ioloop
      $ioloop = $self->ioloop;
      $self = $self->ioloop(Mojo::IOLoop->new);

    Returns the Mojo::IOLoop object.

  listen
      $array_ref = $self->listen;
      $self = $self->listen(['tcp://localhost:3000']);

    List of one or more locations to listen on, defaults to "tcp://*:3000".

  server_class
      $str = $daemon->server_class;
      $self = $self->server_class('Mojo::Server::Prefork');

    Used to set a custom server class. The default is Mojo::Server::Daemon.
    Check out Mojo::Server::Prefork if you want a faster server.

METHODS
  run
      $self = $self->run;

    Start accepting connections and run the server.

  start
      $self = $self->start;

    Start listening for connections. See also "run".

  stop
      $self = $self->stop;

    Stop the server.

AUTHOR
    Jan Henning Thorsen - "jhthorsen@cpan.org"