Storing a socket in an object. 
Author Message
 Storing a socket in an object.

Dear All,
Is it possible to store a socket connection in an object that I have
defined?
Note,
I'm not getting anything back from the socket I am connected to (I'm
not expected to).  Nothing seems to be working so I am wondering if it
is me or the other end of the socket?

Thanks,

Michael.

Here is my object class:

package BServer;
$VERSION = 1.00;
use strict;

use IO::Socket;
use IO::Select;
use Symbol;

use Class::MethodMaker
    new_with_init  => 'new',
    new_hash_init  => '_init_args',
    get_set        => [ qw(port port_no address protocol) ],
    key_attrib     => 'id';

sub init {

    $self->_init_args(%args);
    $self->port(gensym);
    $self->_connect();
    return $self;

Quote:
}

sub _connect{
  my $self = shift;
  my $sock;
  $sock = IO::Socket::INET->new(PeerAddr => $self->address,
                                PeerPort => $self->initial_port,
                                Proto    => $self->protocol);
  $self->port($sock)

Quote:
}

1;

Here is the main progam:

# bs.pl
use BServer;
my $bs = BServer->new(address=>'10.1.16.11',
                      initial_port=>25672,
                      protocol=>'tcp');
my $port = $bs->port();

print $port "Hello";



Mon, 23 Feb 2004 07:48:46 GMT  
 Storing a socket in an object.

Quote:

>Dear All,
>Is it possible to store a socket connection in an object that I have
>defined?
>Note,
>I'm not getting anything back from the socket I am connected to (I'm
>not expected to).  Nothing seems to be working so I am wondering if it
>is me or the other end of the socket?

(snipped code)

your code did not compile on my system.
is there something you are not telling us?

anyways, yes you can store the socket object, just make sure it does
not go out of scope before you have used it.

gnari



Mon, 23 Feb 2004 20:27:19 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Storing object module name in a scalar?

2. Store an object reference as hash key?

3. Storing a filehandle in an object

4. newbie: storing multiple objects in a hash

5. Storing the CGI object in my module?

6. Storing an array as Attribute of object.

7. trouble storing array of objects

8. Storing object attributes in a DB_HASH?

9. Storing object attributes in a DB_HASH?

10. Storing and passing object references

11. compressing objects before storing?

12. Object Store

 

 
Powered by phpBB® Forum Software