################################################################# # This package is an actual found tag package Tag; sub new { my $class = shift; my $self = { _TagID => shift, _ProductName => shift, _ProductDesc => shift, _ProductPrice => shift, }; bless $self, $class; if (0) { print "_TagID:".$self->{_TagID} . "\n"; print "_ProductName:".$self->{_ProductName} . "\n"; print "_ProductDesc:".$self->{_ProductDesc} . "\n"; print "_ProductPrice:".$self->{_ProductPrice} . "\n"; } return $self; } ################################################################# # This package will contain a list of tags. It will handle # managing and expiring tags package TagList; sub new { my $class = shift; my @TagList = (); my $self = { 'TagList' => \@TagList, }; bless $self, $class; return $self; } sub NumberOfTags { my ($self, $value) = @_; return @{$self->{'TagList'}}; } ################################################################# package main; my $CurrentTagList = TagList->new(); bless($CurrentTagList, 'TagList'); my $thr = threads->create(\&http_listen); while() { # read and process tags to fill $CurrentTagList # gets data from a client at a 200 ms interval } ################################################################# # functions for HTTP thread # this will eventually allow a single client to connect and get the tag information at it's own interval sub http_listen { my $http_lsn = new IO::Socket::INET(Listen => 1, LocalPort => 8080, ReuseAddr => 1) || die "Error creating socket: $!"; my $http_sel = new IO::Select( $http_lsn ); my $line = ""; while (my @ready = $http_sel->can_read) { foreach my $fh (@ready) { if ($fh == $http_lsn) { my $new = $http_lsn->accept; $http_sel->add($new); my $host = $new->peerhost; print "[Accepting HTTP connection from $host]\n"; } else { $line = <$fh>; print $line; print 'HTTP - There are ' . $CurrentTagList->NumberOfTags() . ' tags' . "\n\n"; sleep(1); } } } } #################################################################