Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > IO::Socket: buffering error ?

Reply
Thread Tools

IO::Socket: buffering error ?

 
 
galdor
Guest
Posts: n/a
 
      05-26-2005
Hi,

It seems i've a problem with socket-buffering ; i use IO::Socket::INET
to connect a client-program to a server-program, and send orders.

Every connection to the server is well-detected, but every string i
send to the server arrives *only* when i close the client-socket.

I've tried the flush and autoflush method, but result is the same.

Anyone would have an idea ?

 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      05-26-2005
"galdor" <> wrote:
> Hi,
>
> It seems i've a problem with socket-buffering ; i use IO::Socket::INET
> to connect a client-program to a server-program, and send orders.
>
> Every connection to the server is well-detected, but every string i
> send to the server arrives *only* when i close the client-socket.


Sounds like you have a flushing problem.


> I've tried the flush and autoflush method, but result is the same.


Maybe you did it wrong.

> Anyone would have an idea ?


My idea would be make a small complete program which demonstrates the
problem, and show the damn thing to the people you are asking for help.
Maybe that is just me.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
 
 
 
galdor
Guest
Posts: n/a
 
      05-26-2005
You'll find the both client and server program here:
http://darkmaster.sp.free.fr/prog/perl/

galdor

 
Reply With Quote
 
Fabian Pilkowski
Guest
Posts: n/a
 
      05-26-2005
Well, please learn how to quote properly. I know Google is not the best
newsreader you could use, but I've heard there is an option to quote as
recommended. Please, read something about quoting in newsgroups, eg at

http://www.netmeister.org/news/learn2quote.html

It would be in *your* interest to provide some context when composing
contributions to a newsgroup. In the following, I fixed this for you.

* galdor schrieb:
> wrote:
> > galdor wrote:


> > > It seems i've a problem with socket-buffering; i use IO::Socket::INET
> > > to connect a client-program to a server-program, and send orders.
> > > Every connection to the server is well-detected, but every string i
> > > send to the server arrives *only* when i close the client-socket.

> >
> > Sounds like you have a flushing problem.
> >
> > > I've tried the flush and autoflush method, but result is the same.


Well, your server is reading the messages line by line. But how to know
the length of a line? Right, simply add a CRLF ("\r\n") to the rear of
the messages. I prefer to use IO::Socket's capabilities for this (you've
to change the use-statement for IO::Socket::INET for that):

use IO::Socket::INET qw( SOCK_STREAM CRLF );
print $sock_com $comres{"com"}, CRLF;

With that, your server reads the messages when they arrived instead of
reading them when the socket is closed. The CRLF means as much as "this
is the end of this message".

Btw, I suggest to turn on autoflush for STDOUT by writing

$|++;

in the beginning of your script (well, this could be a particularity of
my console on WinXP, but without that I don't see anything on my screen
before the script terminates -- your console's behavior could differ).

> >
> > My idea would be make a small complete program which demonstrates the
> > problem, and show the damn thing to the people you are asking for help.
> > Maybe that is just me.


> You'll find the both client and server program here:
> http://darkmaster.sp.free.fr/prog/perl/


That is not exactly what Xho meant by asking for a "small complete
program". Indeed, they are complete programs, but "small" means to
remove all unnecessary parts of your scripts. Shortening a script is
what *you* should do in order that *we* don't have to search for the
relevant parts in your script.

regards,
fabian
 
Reply With Quote
 
galdor
Guest
Posts: n/a
 
      05-27-2005
Fabian Pilkowski a écrit :
> Well, please learn how to quote properly.

Understood


> Well, your server is reading the messages line by line. But how to know
> the length of a line? Right, simply add a CRLF ("\r\n") to the rear of
> the messages. I prefer to use IO::Socket's capabilities for this (you've
> to change the use-statement for IO::Socket::INET for that):
>
> use IO::Socket::INET qw( SOCK_STREAM CRLF );
> print $sock_com $comres{"com"}, CRLF;
>
> With that, your server reads the messages when they arrived instead of
> reading them when the socket is closed. The CRLF means as much as "this
> is the end of this message".

Fine trick, it's all good, !



> That is not exactly what Xho meant by asking for a "small complete
> program". Indeed, they are complete programs, but "small" means to
> remove all unnecessary parts of your scripts. Shortening a script is
> what *you* should do in order that *we* don't have to search for the
> relevant parts in your script.

Ok, understood too.

Thank's for your help !

galdor

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Double Buffering in ASP.NET Sandeep ASP .Net 2 08-10-2004 04:55 PM
router buffering data before transferring it A. Andrews Cisco 5 02-26-2004 07:34 PM
buffering sam ASP .Net 0 10-29-2003 09:31 PM
Output buffering problems during recursion Tim Mohler Perl 1 09-16-2003 12:35 AM
Page Buffering Strategy? Anthony Bouch ASP .Net 0 07-20-2003 03:42 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57