473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

question about a simple incorrect gab client

i'm reading Network Programming with Perl
there is an example in chapter5:concurrent clients.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use strict;
  3. use IO::Socket qw(:DEFAULT :crlf);
  4.  
  5. my $host=shift or die"Usage:gabl.pl host [port]\n";
  6. my $port=shift || 'tcp';
  7.  
  8. my $socket=IO::Socket::INET->new(PeerAddr=>$host,PeerPort=>$port) or die "can't connect:$!";
  9.  
  10. my($from_server,$from_user);
  11.  
  12. LOOP:
  13. while(1){
  14.         {
  15.         local $/=CRLF;
  16.         last LOOP unless $from_server=<$socket>;
  17.         chomp $from_server;
  18.         }
  19.         print $from_server."\n";
  20.  
  21.         last unless $from_server=<>;
  22.         chomp($from_user);
  23.         print $socket $from_user,CRLF;
  24. }
  25.  
the author said if we change "last LOOP unless $from_server=<$socket>" into a loop like
Expand|Select|Wrap|Line Numbers
  1. while($from_server=<$socket>){
  2.    chomp $from_server;
  3.    print $from_server,"\n";}
  4.  
this will cause a deadlock,this is what the author say
" Now the script hangs after it reads the first line from the server. The FTP server is waiting for us to send it a command, but the script is waiting for another line from the server and hasn't even yet asked us for input, a situation known as deadlock. "
I just don't understand why the script hangs after it reads the first line from the socket if the socket contains more than one line.
Oct 2 '10 #1
1 1210
numberwhun
3,509 Expert Mod 2GB
Well, as the author has stated, if the FTP server is waiting for a command to be issued and at the same time the server has noticed that it hasn't actually been asked for input, its a deadlock.
Oct 8 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Dan | last post by:
I'm writing a simplistic telnet client in VB6 and I've run into a small snag. The program has a textbox to write in the string to be sent using ..SendData and has another textbox that displays...
5
by: Shaul Dar | last post by:
Hi, I am looking for help with the following challenge. We are writing a Smart Client management application, which we want to appear to customers as a Web client. Hence we want to embed it...
7
by: Gooshi | last post by:
Is it possible to write a dead simple html chat client ie one form that can be accessed by two people : ie a form that has two text areas - one for me to write to - one for another person to...
3
by: MBW | last post by:
The following code is for a simple server/client asplication that allows the user to toggle between serve and or client modes and send/recieve a message however i am getting an Attribute error on...
3
by: Billy Bob | last post by:
Hi, does anyone know of a simple ftp client class, should be able to connect and upload/delete files. C# *** Sent via Developersdex http://www.developersdex.com ***
1
by: Nick Gilbert | last post by:
Hi, I'm writing a Windows Forms application in .NET and I need to send an e-mail from it. As it's NOT asp.net, I don't have access to an SMTP server so I will have to send the e-mail using...
1
by: Brian Henry | last post by:
Hello, I was tring to learn socket's (being i never used them before) and have a simple question. I want to create a listner that will get any data recieved and print it out. I've been able to...
4
by: Anne | last post by:
Hi all, I would like to use the ftp protocol to upload a file from 'my' asp server to a ftp server. I'm not able to install components on 'my' server and there are no ftp-components installed....
0
by: Dave | last post by:
Hi, I'm new to Visual Studio and trying to write a simple VB SOAP client. After spending hours of serching the net and the MSDN i can't seem to find a hands on article on how to do this. Is...
0
by: Link | last post by:
hello i want to make simple server client system that send data like that one : http://www.eggheadcafe.com/articles/20020323.asp just no console app well i want to make form with 2...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.