Hi

I have problem in TK module.I am making connection between two system using tcp socket.I am using Tk module as front end.I used these program for chating between two system.After executing my client and server program.My Tk module window is hanged .See my code any help would be appreciated

This is server program

use IO::Socket; use Tk; $| = 1; $socket = new IO::Socket::INET ( LocalHost => '10.101.3.55', LocalPort => '5000', Proto => 'tcp', Listen => 5, Reuse => 1 ); die "Coudn't open socket" unless $socket; print "\nTCPServer Waiting for client on port 5000"; while(1) { $client_socket = ""; $client_socket = $socket->accept(); $peer_address = $client_socket->peerhost(); $peer_port = $client_socket->peerport(); print "\n I got a connection from ( $peer_address , $peer_port ) " +; my ($txt,$mw,$frm_name,$lab,$ent,$txt,$but); $mw= MainWindow->new(); while(1){ #$mw->messageBox(-message=>"TCPServer Waiting for client on po +rt 5000"); $frm_name = $mw -> Frame() -> pack(); $lab = $frm_name -> Label(-text=>"Name:") -> pack(); $ent = $frm_name -> Entry() -> pack(); $txt = $mw -> Text(-width=>40, -height=>10) -> pack(); $but = $mw -> Button(-text=>"Push Me", -command =>sub { while (1) { # print "\n SEND( TYPE q or Q to Quit):"; my $send_data = $ent -> get(); chop($send_data); if ($send_data eq 'q' or $send_data eq 'Q') { $client_socket->send ($send_data); close $client_socket; last; } else { $client_socket->send($send_data); } $client_socket->recv($recieved_data,1024); if ( $recieved_data eq 'q' or $recieved_data eq 'Q') { close $client_socket; last; } else { #print "\n RECIEVED: $recieved_data"; my $data=$recieved_data; $txt -> insert('end',"$data"); } } } )-> pack(); #$but-> pack(); Tk::MainLoop; } }

This is my client program

#!/usr/bin/perl use IO::Socket; use Tk; $socket = new IO::Socket::INET ( PeerAddr => '10.101.3.55', PeerPort => 5000, Proto => 'tcp', ) or die "Couldn't connect to Server\n"; die "Could not connect: $!" unless $socket; my ($txt,$mw,$frm_name,$lab,$ent,$txt,$but); $mw= MainWindow->new(); while (1) { #print "hi\n"; $socket->recv($recv_data,1024); if ($recv_data eq 'q' or $recv_data eq 'Q') { close $socket; last; } else { $frm_name = $mw -> Frame() -> pack(); $lab = $frm_name -> Label(-text=>"Name:") -> pack(); $ent = $frm_name -> Entry() -> pack(); $txt = $mw -> Text(-width=>40, -height=>10) -> pack(); print "RECIEVED: $recv_data"; my $data=$recv_data; $but = $mw -> Button(-text=>"Push Me", -command =>sub { #print "\nSEND( TYPE q or Q to Quit):"; $txt -> insert('end',"$data"); $send_data = $ent -> get(); chop($send_data); if ($send_data ne 'q' and $send_data ne 'Q') { $socket->send($send_data); } else { $socket->send($send_data); close $socket; last; } })->pack(); Tk::MainLoop; } }

Senthil


In reply to hanged In Tk-socket program by senthilkumarperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.