2 #############################################################################
3 ## Name: samples/socket/wxSocketServer.pl
4 ## Purpose: wxSocketServer minimal demo
5 ## Author: Graciliano M. P.
7 ## RCS-ID: $Id: wxSocketServer.pl 2057 2007-06-18 23:03:00Z mbarbon $
8 ## Copyright: (c) 2003-2004 Graciliano M. P.
9 ## Licence: This program is free software; you can redistribute it and/or
10 ## modify it under the same terms as Perl itself
11 #############################################################################
31 my( $frame ) = MyFrame->new( "wxSocket Minimal demo",
32 Wx::Point->new( 50, 50 ),
33 Wx::Size->new( 450, 350 )
36 $this->SetTopWindow( $frame );
46 use Wx qw(:sizer wxTE_MULTILINE );
47 use Wx::Event qw(EVT_BUTTON) ;
49 use Wx qw(wxDefaultPosition wxDefaultSize wxDEFAULT wxNORMAL);
53 my( $this ) = $class->SUPER::new( undef, -1, $_[0], $_[1], $_[2] );
55 my $top_s = Wx::BoxSizer->new( wxVERTICAL );
57 my $text = Wx::TextCtrl->new( $this , -1, '' , wxDefaultPosition, [200,-1] , wxTE_MULTILINE );
58 my $button = Wx::Button->new( $this, -1, 'Start' );
60 $this->{TEXT} = $text ;
62 $top_s->Add( $text , 1, wxGROW|wxALL, 5 );
63 $top_s->Add( $button , 0, wxGROW|wxALL, 0);
65 $this->SetSizer( $top_s );
66 $this->SetAutoLayout( 1 );
68 EVT_BUTTON( $this, $button, \&OnConnect );
84 use Wx::Event qw(EVT_SOCKET_CONNECTION) ;
86 my $sock = Wx::SocketServer->new('localhost',5050,wxSOCKET_WAITALL);
88 EVT_SOCKET_CONNECTION($this , $sock , \&onConnect ) ;
90 my $stat = $sock->Ok ;
91 $this->{TEXT}->AppendText("Ok: <$stat>\n") ;
92 if (! $stat) { return ;}
97 my ( $sock , $this , $evt ) = @_ ;
99 my $client = $sock->Accept(0) ;
101 my @lcaddr = $client->GetLocal ;
102 my @praddr = $client->GetPeer ;
104 $this->{TEXT}->AppendText("-------------------------\n") ;
105 $this->{TEXT}->AppendText("New Client\n") ;
106 $this->{TEXT}->AppendText(" Local: <@lcaddr>\n") ;
107 $this->{TEXT}->AppendText(" Peer: <@praddr>\n") ;
109 $client->Write("This is a data test!\n") ;
112 $this->{TEXT}->AppendText("\n-------------------------(closed)\n") ;
117 my( $app ) = MyApp->new();