flush socket buffer

U

u8526505

I try to write my tcp client to send as many number of bytes as I want
immediately but tcp will not send them until some criteria is met.
After a search of this topic, the mostly mentioned solution is to use
select and autoflush or $|. Another mentions using
syswrite($sock,$buf,1) can work. I've tried all of them but they don't
seem to work. I'm wondering is this a doable task? When we use Telnet
client applications, they can send one character right after when we
hit the keyboard. Does anyone know how they can do it? Thanks.
 
X

xhoster

I try to write my tcp client to send as many number of bytes as I want
immediately but tcp will not send them until some criteria is met.
After a search of this topic, the mostly mentioned solution is to use
select and autoflush or $|. Another mentions using
syswrite($sock,$buf,1) can work. I've tried all of them but they don't
seem to work.

They work for me.
I'm wondering is this a doable task?

For me it is doable. Maybe for you it isn't doable. You certainly aren't
off to a good start.
When we use Telnet
client applications, they can send one character right after when we
hit the keyboard. Does anyone know how they can do it?

By writing the code that does it. Do you actually have code? Can we see
it? For all we know, you tried to type "$|=1" and accidentally mispelled it
as "Hey Diddle diddle the cat played the fiddle".


Xho
 
U

u8526505

(e-mail address removed) 寫é“:

By writing the code that does it. Do you actually have code? Can we see
it? For all we know, you tried to type "$|=1" and accidentally mispelled it
as "Hey Diddle diddle the cat played the fiddle".

below is my code snippet

####
socket(SOCKET, PF_INET, SOCK_STREAM, $proto);
connect(SOCKET, $paddr);
select SOCKET;
$|=1;
print SOCKET 'AAA\n';
print SOCKET 'BBB\n';
print SOCKET 'CCC\n';
####

what I want is that the string in each print statement will be carried
as payload by a network packet. In this case I expect 3 packets to be
sent. But in fact only 2 packets were sent, one carried 'AAA\n' and the
other 'BBB\nCCC\n'.
 
X

xhoster

####
socket(SOCKET, PF_INET, SOCK_STREAM, $proto);

What is $proto set to, in your case?
connect(SOCKET, $paddr);
select SOCKET;
$|=3D1;
print SOCKET 'AAA\n';
print SOCKET 'BBB\n';
print SOCKET 'CCC\n';
####

what I want is that the string in each print statement will be carried
as payload by a network packet.

Why do you want that?
In this case I expect 3 packets to be
sent. But in fact only 2 packets were sent, one carried 'AAA\n' and the
other 'BBB\nCCC\n'.

My interpretation is that Perl sent both BBB\n and CCC\n while the
kernel/socket-layer was still dealing with the processing AAA\n. Once it
was done with AAA\n, it loooked and found both BBB\n and CCC\n in its
buffer and so sent both of them.

And from a previous message:

: When we use Telnet
: client applications, they can send one character right after when we
: hit the keyboard. Does anyone know how they can do it? Thanks.

I don't think this is necessarily true. There is a tremendous difference
between typing speed and CPU speed. If you look at it from the CPU's
perspective, I bet the one character is sent a long time after the key is
hit. Conversly, if your fingers could type as fast as Perl can print, I
bet you would find more than one character per packet in a telnet session.

Xho
 
Y

yl

Hi,
Thanks for all these responses. I have a more clear understanding about
this topic now. I've used Net::packet to solve my problem after all
since it can work on the packet level. The result is exactly as what I
desired.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top