Component of a Server

Key Components of a Server | ServerPronto University
Module Version: 1.367

POE::Component::Server::TCP - a simplified TCP server

#!perl use warnings; use strict; use POE qw(Component::Server::TCP); POE::Component::Server::TCP->new( Port => 12345, ClientConnected => sub { print "got a connection from $_[HEAP]{remote_ip}\n"; $_[HEAP]{client}->put("Smile from the server!"); }, ClientInput => sub { my $client_input = $_[ARG0]; $client_input =~ tr[a-zA-Z][n-za-mN-ZA-M]; $_[HEAP]{client}->put($client_input); }, ); POE::Kernel->run; exit;

POE::Component::Server::TCP implements a generic multi-Session server. Simple services may be put together in a few lines of code. For example, a server that echoes input back to the client:

use POE qw(Component::Server::TCP); POE::Component::Server::TCP->new( Port => 12345, ClientInput => sub { $_[HEAP]{client}->put($_[ARG0]) }, ); POE::Kernel->run;

POE::Component::Server::TCP has a default mode where it accepts new connections and creates the sessions to handle them. Programs can do this themselves by providing their own Acceptor callbacks. See for details.

At creation time, POE::Component::Server::TCP starts one POE::Session to listen for new connections. The component's Alias refers to this master session.

If Acceptor is specified, then it's up to that callback to deal with newly accepted sockets. Its parameters are that of POE::Wheel::SocketFactory's SuccessEvent.

Otherwise, the default Acceptor callback will start a new session to handle each connection. These child sessions do not have their own aliases, but their ClientConnected and ClientDisconnected callbacks may be used to register and unregister the sessions with a shared namespace, such as a hash keyed on session IDs, or an object that manages such a hash.

my %client_namespace; sub handle_client_connected { my $client_session_id = $_[SESSION]->ID; $client_namespace{$client_session_id} = \%anything; } sub handle_client_disconnected { my $client_session_id = $_[SESSION]->ID; $client_namespace{$client_session_id} = \%anything; }

The component's Started callback is invoked at the end of the master session's start-up routine. The @_[ARG0..$#_] parameters are set to a copy of the values in the server's ListenerArgs constructor parameter. The other parameters are standard for POE::Session's _start handlers.

The component's Stopped callback is invoked at the beginning of the master session's _stop routine. The parameters are standard for POE::Session's _stop handlers.

The component's Error callback is invoked when the server has a problem listening for connections. Error may also be called if the component's default acceptor has trouble accepting a connection. Error receives the usual ones for "FailureEvent" in POE::Wheel::SocketFactory and "ErrorEvent" in POE::Wheel::ReadWrite.

If Acceptor isn't specified, POE::Component::Server::TCP's default handler will start a new session for each new client connection. As mentioned above, these child sessions have no aliases of their own, but they may set aliases or register themselves another way during their ClientConnected and ClientDisconnected callbacks.

Startech StarTech.com 25U Adjustable Depth Open Frame 4 Post Server Rack Cabinet with Casters/Levelers and Cable Management Hooks 4POSTRACK25U Black
Personal Computer (Startech)
  • Store your servers network and telecommunications equipment in this adjustable 25U rack
  • 25U Adjustable Depth Open Frame 4 Post Server Rack Cabinet
  • Flat Pack w/ Casters Levelers Cable Management Hooks
  • 4 Post Rack
  • 25U Server Rack
  • Supports a static loading capacity of 1200lbs (544kg)
  • Easy-to-read Unit (U) and depth adjustment markings
  • Mount your equipment easily, with clearly marked rack units (U) and depth
  • Adapt the rack to your equipment easily, with an adjustable depth design
  • Customize the rack to fit your environment using the included optional accessories
Update International Update International RS-4SS Relish Server, 4 Components Gift Box
BISS (Update International)
  • Made of stainless steel
  • Rotating base
  • Four compartments with jars, lids, and spoons
Royal Racks Rolling Equipment Rack 42U - Built in Casters/Wheels - Open Skeleton - Professional Use Electronics/Audio Video/Server/Switch
Furniture (Royal Racks)
  • 42U Rolling Equipment Rack - Pre-installed 3 Locking Non-Marring Casters (why worry about finding a wheel kit?)
  • Durable, scratch-resistant black matte powder-coated finish
  • Top plate has knock-outs for easy mounting of fan kits
  • Metric/Standard threaded bars - Detachable Bottom plate has knock outs for wire access
  • Dimensions (HxWxD) by inch (79.92 x 20.5 x 18 ) Comes with 168 Extra screws for equipment shelves!!
Microsoft Press Developing Microsoft® ASP.NET Server Controls and Components (Developer Reference)
Book (Microsoft Press)
  • ISBN13: 9780735615823
  • Condition: New
  • Notes: BRAND NEW FROM PUBLISHER! 100% Satisfaction Guarantee. Tracking provided on most orders. Buy with Confidence! Millions of books sold!
Dow LP537 Dickies Ultimate Server Cargo Pant BLACK 30X34
BISS (Dow)
  • Mid-rise, sits below waist
  • Resists wrinkles, easy care stain release
  • stronger, wider belt loops
  • pleated cargo pkt w/hidden snap
  • 7¼ oz twill, 65/35 poly/cotton blend

Related posts: