This program is just a beginner I'm not sure if this is how I want it to work quit yet. The error I get with this program is:#!/usr/bin/perl use warnings; use strict; use IO::Socket; use Gtk2 -init; use Glib qw/TRUE FALSE/; my $main_window = Gtk2::Window->new("toplevel"); $main_window->signal_connect(delete_event => sub{Gtk2->main_quit}); my $buffer = Gtk2::TextBuffer->new; my $table = Gtk2::Table->new(3, 2, FALSE); my $label = Gtk2::Label->new("Chat Client Test"); my $textview = Gtk2::TextView->new_with_buffer($buffer); my $swindow = Gtk2::ScrolledWindow->new( undef, undef); $swindow->set_size_request (100, 150); my $button = Gtk2::Button->new("Send"); my $entry = Gtk2::Entry->new(); $textview->set_cursor_visible (FALSE); $textview->set_editable(FALSE); $buffer->create_mark ('end', $buffer->get_end_iter, FALSE); $buffer->signal_connect (insert_text => sub {$textview->scroll_to_mark + ($buffer->get_mark ('end'),0.0, TRUE, 0, 0.5)}); $swindow->set_policy( 'automatic', 'automatic'); $swindow->set_shadow_type( 'etched-out'); $swindow->add( $textview); $table->attach_defaults($label, 0, 1, 0, 1); $table->attach_defaults($swindow, 0, 2, 1, 2); $table->attach_defaults($entry, 0, 1, 2, 3); $table->attach_defaults($button, 1, 2, 2, 3); $main_window->add($table); $main_window->show_all(); $button->signal_connect("clicked" =>sub { #get the contents of the entry my $msg_send = $entry->get_text; #clear the entry $entry->set_text(""); #grab focus again for the next round of talks $entry->grab_focus; #if there was bogus input, ignore it! if ($msg_send !~ m/^\s*$/){ #open up a UDP client connection my $SEND_PORT = 5152; my $server_host = "Deadpickle-hobo"; my $sock = IO::Socket::INET->new(Proto => 'udp', PeerP +ort => $SEND_PORT, PeerAddr => $server_host) or die "Creating socke +t: $!\n"; #send the message out on the socket $sock->send($msg_send."\n") or die "send: $!"; #update the screen locally #&update_buffer($buffer,$msg_send,TRUE); } }); Gtk2->main;
Any ideas on how to get this to work correctly?#!/usr/bin/perl -w use strict; use IO::Socket; use Gtk2 -init; use Glib qw/TRUE FALSE/; use Gtk2::Helper; my($sock,$MAXLEN, $LISTEN_PORT, $SEND_PORT,$tag_send,$tag_receive,$im +g_big,$img_send,$img_rec); $MAXLEN = 1024; $LISTEN_PORT = 5151; my $tview; #set up a udp server waiting for incomming messages $sock = IO::Socket::INET->new(LocalPort => $LISTEN_PORT, Proto => 'ud +p') or die "socket: $@"; #add a Gtk2::Helper watch on any incomming connections Gtk2::Helper->add_watch ( fileno $sock, 'in',$sock); print "Awaiting UDP messages on port $LISTEN_PORT\n";
In reply to Building a chat server and client by deadpickle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |