1 #############################################################################
2 ## Name: samples/socket/wxSocketServer.pl
3 ## Purpose: wxSocketServer minimal demo
4 ## Author: Graciliano M. P.
6 ## RCS-ID: $Id: wxSocketServer.pl 2057 2007-06-18 23:03:00Z mbarbon $
7 ## Copyright: (c) 2003-2004 Graciliano M. P.
8 ## Licence: This program is free software; you can redistribute it and/or
9 ## modify it under the same terms as Perl itself
10 #############################################################################
30 my( $frame ) = MyFrame->new( "wxSocket Minimal demo",
31 Wx::Point->new( 50, 50 ),
32 Wx::Size->new( 450, 350 )
35 $this->SetTopWindow( $frame );
45 use Wx qw(:sizer wxTE_MULTILINE );
46 use Wx::Event qw(EVT_BUTTON) ;
48 use Wx qw(wxDefaultPosition wxDefaultSize wxDEFAULT wxNORMAL);
52 my( $this ) = $class->SUPER::new( undef, -1, $_[0], $_[1], $_[2] );
54 my $top_s = Wx::BoxSizer->new( wxVERTICAL );
56 my $text = Wx::TextCtrl->new( $this , -1, '' , wxDefaultPosition, [200,-1] , wxTE_MULTILINE );
57 my $button = Wx::Button->new( $this, -1, 'Start' );
59 $this->{TEXT} = $text ;
61 $top_s->Add( $text , 1, wxGROW|wxALL, 5 );
62 $top_s->Add( $button , 0, wxGROW|wxALL, 0);
64 $this->SetSizer( $top_s );
65 $this->SetAutoLayout( 1 );
67 EVT_BUTTON( $this, $button, \&OnConnect );
83 use Wx::Event qw(EVT_SOCKET_CONNECTION) ;
85 my $sock = Wx::SocketServer->new('localhost',5050,wxSOCKET_WAITALL);
87 EVT_SOCKET_CONNECTION($this , $sock , \&onConnect ) ;
89 my $stat = $sock->Ok ;
90 $this->{TEXT}->AppendText("Ok: <$stat>\n") ;
91 if (! $stat) { return ;}
96 my ( $sock , $this , $evt ) = @_ ;
98 my $client = $sock->Accept(0) ;
100 my @lcaddr = $client->GetLocal ;
101 my @praddr = $client->GetPeer ;
103 $this->{TEXT}->AppendText("-------------------------\n") ;
104 $this->{TEXT}->AppendText("New Client\n") ;
105 $this->{TEXT}->AppendText(" Local: <@lcaddr>\n") ;
106 $this->{TEXT}->AppendText(" Peer: <@praddr>\n") ;
108 $client->Write("This is a data test!\n") ;
111 $this->{TEXT}->AppendText("\n-------------------------(closed)\n") ;
116 my( $app ) = MyApp->new();