473,382 Members | 1,392 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

creating Handles

I am coding for a server. After server is reading a particluar port,
How can I create handles for them and distinguish them individually
#!/usr/local/bin/perl -w

use strict;
use IO::Socket;
use IO::Select;
use IO::Handle;

# create a socket to listen to a port
my $listen = IO::Socket::INET->new(Proto => 'tcp',
LocalPort => 2323,
Listen => 1,
Reuse => 1) or die $!;

# to start with, $select contains only the socket we're listening on
my $select = IO::Select->new($listen);

my @ready;

# wait until there's something to do
while(@ready = $select->can_read)
{

my $socket;

# handle each socket that's ready
for $socket (@ready)
{

# if the listening socket is ready, accept a new connection
if($socket == $listen)
{
my $new = $listen->accept;
$select->add($new);
print "Select= $select, \n";
print $new->fileno. ": connected\n";

}
else
{

# otherwise, read a line of text and send it back again
my $line="";
$socket->recv($line,80);
print "\nReceived at Server:$line";
$line ne "" and $socket->send($line) or do
{
# either can't send or can't receive, so they must have hung up
print $socket->fileno . ": disconnected\n";
$select->remove($socket);
$socket->close;
exit;
};
}
}
}
Jul 19 '05 #1
1 2293
ak**********@yahoo.com (SRam) wrote in message news:<20**************************@posting.google. com>...
Subject: creating Handles
I do not think that your question is about creating handles.
I am coding for a server. After server is reading a particluar port,
How can I create handles for them and distinguish them individually


I do not understand the question - the code you have written seems to
do just that.

I suspect you were wanting to asking was how to store application
level information assocuated with a socket so that you can retrieve it
when IO::Select passed you a ready handle.

If you use a Perl object reference (other than an object that uses
overload) in a string context it will return a string that can be
assumed to uniquely define that object so long as the object exists.

You can therefore use object references as hash keys.

my $new = $listen->accept;
$socket_info{$new}{FOO} = 'bar';

You need to remember to delete the entry in %socket_info when you
destroy the IO::Socket object.

Alternatively, objects that are based on GLOBS (such as IO::Socket
objects) have spare storage capacity. You can exploit this. The HASH
knob is already used by IO::*, but you can hang private data off the
SCALAR knob.

my $new = $listen->accept;
${*$new}->{FOO}='bar';

You could also use an ARRAY keyed on fileno but this would be
pathologically bad if you ever used a platform where sockets are given
high filenos.

This newsgroup does not exist (see FAQ). Please do not start threads
here.
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Don | last post by:
hi in the past (vb 5.0) is used to create applications with multiple forms. i would hide and/or show the appropriate form depending on user input. now i'm using vb.net (still getting used to it)...
2
by: vivek | last post by:
Hello Every body, I am tring to make an array of server controls with array indes can change dynamically. But I was not able to get the refrence of the control outside the scope in which they...
2
by: DaWoE | last post by:
Hi all, I'm fairly new to ASP.NET. What i want to do is creat a online registration form. On the first step is getting the users details and the number of people he wants to register. Based on...
0
by: Steve | last post by:
Some end users are getting the following message after being in the application for quite some time. Exception Type: System.ComponentModel.Win32Exception NativeErrorCode: 14 ErrorCode:...
4
by: Jeffrey Spoon | last post by:
Hello. I have been working on the program below. However I'm not sure how to get my own event working properly. I created my ThresholdNormal class and put a condition in the sub CheckThreshold. It...
2
by: av | last post by:
im having a hard time creating a timer in vb.net.. the program should run this way: the timer should only start when you press a button then stops when presing it again.. my problem is that, how...
5
by: SalamElias | last post by:
I am creating several chkBoxes dynamically and assigning an event handler in the Page_load as foillows ***************************** Dim chkCatOption As CheckBox = New CheckBox chkCatOption.Text...
2
by: Jonathan Boivin | last post by:
Hi people, Let me introduce to how I get this error. I have a form which load all my bills representation depending upon filters which each bill is a usercontrol of my own having some...
0
by: Bomac8 | last post by:
I have a text file with "|" as a delimeter with three (3) fields XXX-12345|\\YYYYYYY|\\ZZZZZZZZ I need to read these files into an output folder. The problem that I'm having is that I need to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.