I have a TCP Socket beetwen two programs, a C# server and a Perl client. The client is supposed to receive an XML stream from the server. The XML file (generated by the C# program) is around 437KB but the client only receives 408KB no matter how big is the buffer. On the client side I use IO::Socket::INET while the server side uses a combination of TcpListener and TcpClient. How can I properly define the buffer on the client side? Right now I am using that code:
# PERL CLIENT
my $socket = new IO::Socket::INET (
PeerHost => '192.168.*.*',
PeerPort => '*****',
Proto => 'tcp'
) or die "Error while creating Socket";
#
# OTHER STUFFS...
#
my $buffer = 500000000; # IT DOESNT SEEM TO USE THAT VALUE AT ALL
$socket->recv($xmlbody, $buffer);
// C# SERVER
// OTHER STUFFS...
byte[] result = encoding.GetBytes(xml);
clientStream.Write(result, 0, result.Length);
clientStream.Flush();
clientStream.Close();
tcpClient.Close();
I never use
recv, so I don’t know its quirks. I usesysread.If this doesn’t do it, I suggest you use
tcpdumpto ascertain whether the problem is in the sender, the receiver, or somewhere in between.sysread‘s andread‘s “quirks”:sysreadalways returns as soon as bytes bytes available, regardless of how many bytes were requested. That means it returns immediately if bytes are already available when it is called. It will block until a packet comes in otherwise. That means one needs to loop if one wants a specific number of characters.In contrast,
readwaits until the requested number of bytes are available. It only returns then, on EOF or on error.readandsysreadactually work at the character level, which means you actually specify a number of characters desired, not a number of bytes. Those characters could be bytes, Unicode code points or whatever depending on what IO layer you added to the handle.