Manual Pages for UNIX Darwin command on man Wx::Socket
MyWebUniversity

Manual Pages for UNIX Darwin command on man Wx::Socket

Wx::Socket(3) User Contributed Perl Documentation Wx::Socket(3)

NAME

Wx::Socket - wxSocket* classes

UUSSAAGGEE use Wx qw(:socket) ;

use Wx::Event qw(EVTSOCKETINPUT EVTSOCKETLOST) ;

use Wx::Event qw(EVTSOCKETCONNECTION) ;

##########

# CLIENT #

##########

my $sock = Wx::SocketClient->new(wxSOCKETWAITALL);

EVTSOCKETINPUT($parent , $sock , \&onInput ) ;

EVTSOCKETLOST($parent , $sock , \&onClose ) ;

$sock->Connect('localhost',5050) ;

if (! $sock->IsConnected ) { print "ERROR\n" ;}

sub onInput {

my ( $sock , $this , $evt ) = @ ;

my $length = 123;

my $buffer ;

$sock->Read($buffer , 1024 , $length ) ;

}

##########

# SERVER #

##########

my $sock = Wx::SocketServer->new('localhost',5050,wxSOCKETWAITALL);

EVTSOCKETCONNECTION($parent , $sock , \&onConnect ) ;

if ( !$sock->Ok ) { print "ERROR\n" ;}

sub onConnect {

my ( $sock , $this , $evt ) = @ ;

my $client = $sock->Accept(0) ;

my ($localhost,$localport) = $client->GetLocal ;

my ($peerhost,$peerport) = $client->GetPeer ;

$client->Write("This is a data test!\n") ;

... or ...

$client->Write( $data , length($data) ) ;

$client->Close ;

} MMEETTHHOODDSS All the methods work as in wxWidgets (see the documentation). The functions for reading data (Read, ReadMsg, Peek) take 3 arguments, like the Perl read() function:

## To read the data into the variable

$sock->Read($buffer , 1024) ;

... or ...

## To append data at the given offset:

$sock->Read($buffer , 1024 , $offset ) ;

The write functions (Write, WriteMsg, Unread) can be used with 1 or 2 arguments:

$client->Write("This is a data test!\n") ;

$client->Write($data , $length) ;

EEVVEENNTTSS The events are: EVTSOCKET EVTSOCKETALL

EVTSOCKETINPUT

EVTSOCKETOUTPUT

EVTSOCKETCONNECTION EVTSOCKETLOST The EVTSOCKET works as in wxWidgets, the others are wxPerl extensions. Note that EVTSOCKET events of wxSocketClient and wxSocketServer work differently than other event types. First you need to set the event handler:

$sock->SetEventHandler($handler, $id) ;

Then you set what types of event you want to receive:

## this select all.

$sock->SetNotify(wxSOCKETINPUTFLAG|wxSOCKETOUTPUTFLAG|

wxSOCKETCONNECTIONFLAG|wxSOCKETLOSTFLAG) ; Enable the event notification:

$sock->Notify(1) ;

And only after this use:

## note that $handler must be the same that was used in

## SetEventHandler

EVTSOCKET($handler, $id , sub{...} )

To make the events easier to use, all the proccess is automatic, and you just use:

EVTSOCKETINPUT($handler , $socket , sub{...} )

EVTSOCKETOUTPUT($handler , $socket , sub{...} )

EVTSOCKETCONNECTION($handler , $socket , sub{...} )

EVTSOCKETLOST($handler , $socket , sub{...} )

## This is for the events not used yet by the above:

EVTSOCKETALL($parent , $socket , sub{...} )

** The new way is better to handle more than one socket in the same time too. Take a look in the demos.

SEE ALSO

Wx, The wxWxwindows documentation at AUTHOR Graciliano M. P. COPYRIGHT This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

perl v5.8.8 2004-02-28 Wx::Socket(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™