Re: Newbie needs help with IO::Socket (maybe IO::Select)



"Boerni" <john@xxxxxxx> wrote:
Hi all

I'm playing around with IO::Socket and try to build a small Client/Server
App.

The Serverpart is working as it's supposed to, but I have some problems
with the Clientpart.

So I have a couple of Questions:
1. How can a Client react to a Servermessage (Server prints to Socket),
when it's not expecting a Servermessage (For example another client
connects to the server and kicks the first one or the server is beeing
shutdown).

Why would another client connecting to the server kick off the first one?
Wouldn't it be easier to fix this problem than to deal with the
consequences?

If the server has gone away, the client will realize this next time it
tries to communicate with it. While I guess it might be nice to know
immediately that the server has gone away, plenty of very good
client-server apps don't detect server failure until the next time it tries
to communicate. I'd need a very compelling reason not to follow this
paradigm for my own clients.

If I use the IO::Select approach like in the Serverpart, the
Client is blocked and the User can't interact with it anymore.

You need to add STDIN (or whatever you use to communicate with the User)
into the IO::Select, too. This means you probably have to use sysread,
rather than <>, to read from STDIN.

.....

#Pruefen ob ein Client connectet
while(1) {
my ($neu_lesbare) = IO::Select->select($lesbar, undef, undef, undef);

foreach $socket(@{$neu_lesbare}) {
if ($socket == $main_socket) {
#Neue Verbindung kommt rein...
my $neues_socket = $socket->accept();
$lesbar->add($neues_socket);
}
else {
# Hier drin passiert Zeug mit dem Client
my $buf = <$socket>;

You are mixing buffered IO with select. This is rather dangerous. If
the client can ever print two (or more) lines into $socket in quick
succession, then this code might cause both of them to be read into the
perl internal buffer, but only one of them to be returned from there
into $buf. The next line just sits in the internal buffer, where it will
not trigger IO::Select and hence not get read. The client won't send any
more lines (which would trigger IO::Select) because it is waiting for a
response to the last line it sent, and the server will never respond to
that line because it doesn't know that it is there. Deadlock.

I think IO::Select (or some subclass thereof) should return readable for
any file handle that has data sitting in the perl internal buffer, in
addition to the handles that have data (or eof) in the system's buffers. I
haven't quite figured out how to implement that. All of those globs and
glob refs and PerlIO layers and tied handles and scalar masquerading as
handles are just too much for me.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
.



Relevant Pages

  • RE: Using kerberosSecurity Throws Security Exception
    ... I am experiencing this error while trying to use a Windows XP client ... application to access a web service located on a W2k3 server. ... client app on the server, ... > Account with a Custom Principal Name using SetSPN.exe utility. ...
    (microsoft.public.dotnet.framework.webservices.enhancements)
  • Re: Questions about Remoting, objects, threading. lease lifetime and object cleanup, and a couple of
    ... so long as the Client app is ... always refering to the same server object. ... it sets its ClassOne object to nothing and goes away. ... >>The client app at some point is going to become an ASP.Net app also. ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Remoting or windows service
    ... Thanks for writing up such a decent overview of the remoting dev process ... the client and the server. ... > 2) Implement this class in the server app and say that it can be accessed ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: What doesnt lend itself to OO?
    ... >> proxy and instructs the server to constuct the real object. ... rather than client code. ... If 'clock' is instantiated in the server, ... > for the server interface at the OOA level. ...
    (comp.object)
  • Re: Schannel and Session Renegotiation
    ... Schannel does not support the server sending app ... We are discussing the option of providing support for the client blowing off ...
    (microsoft.public.platformsdk.security)