1 #############################################################################
2 ## Name: samples/socket/wxSocketClientDatagram.pl
3 ## Purpose: wxDatagramSocket minimal demo
4 ## Author: Graciliano M. P., Mattia Barbon
6 ## RCS-ID: $Id: wxSocketClientDatagram.pl 2057 2007-06-18 23:03:00Z mbarbon $
7 ## Copyright: (c) 2004 Graciliano M. P., Mattia Barbon
8 ## Licence: This program is free software; you can redistribute it and/or
9 ## modify it under the same terms as Perl itself
10 #############################################################################
23 my( $frame ) = MyFrame->new( "wxSocket Minimal demo",
24 Wx::Point->new( 50, 50 ),
25 Wx::Size->new( 450, 350 )
28 $this->SetTopWindow( $frame );
38 use Wx qw(:sizer wxTE_MULTILINE );
39 use Wx::Event qw(EVT_BUTTON) ;
41 use Wx qw(wxDefaultPosition wxDefaultSize wxDEFAULT wxNORMAL);
45 my( $this ) = $class->SUPER::new( undef, -1, $_[0], $_[1], $_[2] );
47 my $top_s = Wx::BoxSizer->new( wxVERTICAL );
49 my $text = Wx::TextCtrl->new( $this , -1, '' , wxDefaultPosition, [200,-1] , wxTE_MULTILINE );
50 my $button = Wx::Button->new( $this, -1, 'Connect' );
52 $this->{TEXT} = $text ;
54 $top_s->Add( $text , 1, wxGROW|wxALL, 5 );
55 $top_s->Add( $button , 0, wxGROW|wxALL, 0);
57 $this->SetSizer( $top_s );
58 $this->SetAutoLayout( 1 );
60 EVT_BUTTON( $this, $button, \&OnConnect );
76 use Wx::Event qw(EVT_SOCKET_INPUT EVT_SOCKET_LOST) ;
78 my $addr = Wx::IPV4address->new;
79 $addr->SetHostname( 'localhost' );
80 $addr->SetService( 5555 );
81 my $sock = Wx::DatagramSocket->new( $addr );
83 EVT_SOCKET_INPUT($this , $sock , \&onInput ) ;
85 my $addr2 = Wx::IPV4address->new;
86 $addr->SetHostname( 'localhost' );
87 $addr->SetService( 4444 );
88 $sock->SendTo( $addr, "123456\n", 7 );
90 $this->{TEXT}->AppendText("-------------------------\n") ;
94 my ( $sock , $this , $evt ) = @_ ;
96 my $addr = Wx::IPV4address->new;
97 while( $sock->RecvFrom( $addr, $buf , 1000 ) ) {
98 if ($buf =~ /\n$/s) { last ;}
100 $this->{TEXT}->AppendText($buf."#END#") ;
106 my( $app ) = MyApp->new();