.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Wx::Socket 3pm" .TH Wx::Socket 3pm 2024-04-11 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Wx::Socket \- wxSocket* classes .SH USAGE .IX Header "USAGE" .Vb 3 \& use Wx qw(:socket) ; \& use Wx::Event qw(EVT_SOCKET_INPUT EVT_SOCKET_LOST) ; \& use Wx::Event qw(EVT_SOCKET_CONNECTION) ; \& \& ########## \& # CLIENT # \& ########## \& \& my $sock = Wx::SocketClient\->new(wxSOCKET_WAITALL); \& \& EVT_SOCKET_INPUT($parent , $sock , \e&onInput ) ; \& EVT_SOCKET_LOST($parent , $sock , \e&onClose ) ; \& \& $sock\->Connect(\*(Aqlocalhost\*(Aq,5050) ; \& \& if (! $sock\->IsConnected ) { print "ERROR\en" ;} \& \& sub onInput { \& my ( $sock , $this , $evt ) = @_ ; \& my $length = 123; \& my $buffer ; \& $sock\->Read($buffer , 1024 , $length ) ; \& } \& \& ########## \& # SERVER # \& ########## \& \& my $sock = Wx::SocketServer\->new(\*(Aqlocalhost\*(Aq,5050,wxSOCKET_WAITALL); \& \& EVT_SOCKET_CONNECTION($parent , $sock , \e&onConnect ) ; \& \& if ( !$sock\->Ok ) { print "ERROR\en" ;} \& \& sub onConnect { \& my ( $sock , $this , $evt ) = @_ ; \& my $client = $sock\->Accept(0) ; \& \& my ($local_host,$local_port) = $client\->GetLocal ; \& my ($peer_host,$peer_port) = $client\->GetPeer ; \& \& $client\->Write("This is a data test!\en") ; .Ve .PP \&... or ... .PP .Vb 1 \& $client\->Write( $data , length($data) ) ; \& \& $client\->Close ; \& } .Ve .SH METHODS .IX Header "METHODS" All the methods work as in wxWidgets (see the documentation). .PP The functions for reading data (Read, ReadMsg, Peek) take 3 arguments, like the Perl \fBread()\fR function: .PP .Vb 2 \& ## To read the data into the variable \& $sock\->Read($buffer , 1024) ; .Ve .PP \&... or ... .PP .Vb 2 \& ## To append data at the given offset: \& $sock\->Read($buffer , 1024 , $offset ) ; .Ve .PP The write functions (Write, WriteMsg, Unread) can be used with 1 or 2 arguments: .PP .Vb 1 \& $client\->Write("This is a data test!\en") ; \& \& $client\->Write($data , $length) ; .Ve .SH EVENTS .IX Header "EVENTS" The events are: .PP .Vb 6 \& EVT_SOCKET \& EVT_SOCKET_ALL \& EVT_SOCKET_INPUT \& EVT_SOCKET_OUTPUT \& EVT_SOCKET_CONNECTION \& EVT_SOCKET_LOST .Ve .PP The EVT_SOCKET works as in wxWidgets, the others are wxPerl extensions. .PP Note that EVT_SOCKET events of wxSocketClient and wxSocketServer work differently than other event types. .PP First you need to set the event handler: .PP .Vb 1 \& $sock\->SetEventHandler($handler, $id) ; .Ve .PP Then you set what types of event you want to receive: .PP .Vb 3 \& ## this select all. \& $sock\->SetNotify(wxSOCKET_INPUT_FLAG|wxSOCKET_OUTPUT_FLAG| \& wxSOCKET_CONNECTION_FLAG|wxSOCKET_LOST_FLAG) ; .Ve .PP Enable the event notification: .PP .Vb 1 \& $sock\->Notify(1) ; .Ve .PP And only after this use: .PP .Vb 3 \& ## note that $handler must be the same that was used in \& ## SetEventHandler \& EVT_SOCKET($handler, $id , sub{...} ) .Ve .PP To make the events easier to use, all the process is automatic, and you just use: .PP .Vb 4 \& EVT_SOCKET_INPUT($handler , $socket , sub{...} ) \& EVT_SOCKET_OUTPUT($handler , $socket , sub{...} ) \& EVT_SOCKET_CONNECTION($handler , $socket , sub{...} ) \& EVT_SOCKET_LOST($handler , $socket , sub{...} ) \& \& ## This is for the events not used yet by the above: \& EVT_SOCKET_ALL($parent , $socket , sub{...} ) .Ve .PP ** The new way is better to handle more than one socket in the same time too. Take a look in the demos. .SH "SEE ALSO" .IX Header "SEE ALSO" Wx, The wxWxwindows documentation at .SH AUTHOR .IX Header "AUTHOR" Graciliano M. P. .SH COPYRIGHT .IX Header "COPYRIGHT" This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.