tags:

views:

36

answers:

1

I'm using perl to write a socket based application. I found that if the client iniate two print on the socket handle in a way as below:

print $sock "hello kitty";
#do some other stuff
print $sock "hello jack";

the server side can't receive the whole message of "hello kitty". I'm not sure, but strongly suspicious that there are buffer overwrite happend somewhere... so I have two questiones here

  1. why the data is lost? is it because "print" has a limited size of buf?
  2. how to avoid it? I can accept other method other than the print way
+1  A: 

My immediate guess is that the socket may be in line-buffered mode and is waiting for you to print a newline (or fill the buffer) before sending data to the other side. If that's the case, then print $sock "hello kitty\n"; should get it working as you intend.

However, as daxim commented, there's no way for us to be sure without seeing all the relevant code, including (but not limited to) how you're creating the socket.

Dave Sherohman