Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Client & Server Sockets - String Length limitation ?

728 views
Skip to first unread message

Luke Grews

unread,
Jan 11, 1999, 3:00:00 AM1/11/99
to

Hi

Please could you advise: We are using the server and client sockets in
delphi 4 C/S. We are sending a large string over the network which is larger
than 140k. The message is comming out on the other side in a corrupted
state. Is there a limitation on the length of the string sent with these
sockets ? If so how do we get around it ?

Thanks

Luke Grews

Gordon Hamm

unread,
Jan 11, 1999, 3:00:00 AM1/11/99
to
Are you getting the length that you expect but just corrupted or is it the
wrong length?
Maybe you can post the method that sends the string as well as the receive
side.

--
Gordon Hamm
Voice Data Systems Inc.
360-686-8315
Luke Grews wrote in message <77df05$oa...@forums.borland.com>...

Stig Johansen

unread,
Jan 12, 1999, 3:00:00 AM1/12/99
to
Hi.
Sending one large string, will risk to be terminated by a timeout.
Try to send it in smaller pieces ( i.e. 4096 ).
Also be sure to send info about the length.
Regards
Stig Johansen.

Bob Whitaker

unread,
Jan 12, 1999, 3:00:00 AM1/12/99
to
I had problems with large messages, too. In my TClientSocket's OnRead event, I
was using the Socket parameter's ReceiveText method to read the incoming data.
My problem only occurred when the incoming message (in total bytes) was greater
than 8192 *AND* one of the arriving packets was equal to 8192 bytes.

e.g. - Socket.ReceiveText returned a string having a length of 8192.

What I found was - the actual length of the data received was *LESS THAN* 8192.
The length of the string returned from the ReceiveText method was 8192, but the
"recv" function that read from the socket did not get that many bytes. [I
learned this from using a program called SocketSpy (www.win-tech.com)]

My solution was to use the ReceiveBuf method instead of the ReceiveText. I have
posted my OnRead event below. It is from a C++ Builder project, but the
underlying VCL is the same; the C++ should be easy to follow.

I would be interested to learn if this is the same problem that you are
experiencing, and if there are other folks out there that have had this problem.

Now for the code...

The code snippet uses the following types/variables/functions:
TReadBuffer is a byte array of size 65535
FReadBuffer is of type TReadBuffer
DDataFromLLC is an AnsiString;
//---------------------------------------------------------------------------
void __fastcall CLowLevelController::ClientSocketRead(TObject *Sender,
TCustomWinSocket *Socket)
{

/* leave this code around for reference, there is a problem with it (see below)

AnsiString data = Socket->ReceiveText();
if (DEcho) {
Logit("Bytes received: "+IntToStr(data.Length()));
}
DDataFromLLC += data;
ProcessIncomingData();
*/

// note: "AnsiString data = Socket->ReceiveText()" is unreliable,
// it sometimes reports 8192 bytes received, when < 8192 is actually
received
int received = Socket->ReceiveBuf((char*)FReadBuffer,sizeof(TReadBuffer));
if (received > 0) {
AnsiString data = "";
data.SetLength(received);
Move(FReadBuffer,(void*)&data[1],received);

if (DEcho) {
Logit("Bytes received: "+IntToStr(data.Length()));
}

DDataFromLLC += data;
ProcessIncomingData();
}
}
//---------------------------------------------------------------------------

I hope this helps.

Bob

Cyd Lantz

unread,
Jan 13, 1999, 3:00:00 AM1/13/99
to
I was cruising around Inprise's site yesterday looking for information, and
came upon a tech document saying the sockets are limited to 8k at a crack.
I wonder if that's what you're experiencing.

I did a search on 'TClient' & limited my search to Delphi...

Cheers,
Cyd

Bob Whitaker wrote in message <369B539B...@ornl.gov>...

Gordon Hamm

unread,
Jan 13, 1999, 3:00:00 AM1/13/99
to
Ok, I combed through the code today a little. In the code, Send() and Recv()
are allowing you to pass any buffer size. This is dangerous as winsock has
as a Default a internal buffer of 8192. There I think there needs to be some
sort of loop that only passes 8 k at a time to Send(). I remember now why I
wrote my own server <g>

JPH

unread,
Jan 14, 1999, 3:00:00 AM1/14/99
to
the TCP/IP receive buffer is limited to 8Ko but
it is possible to send message larger than 8Ko.

1/

when you send your large buffer (140Ko) in one time, TCP/IP cut it
in several small buffer (size < 8Ko) and send them on
the socket connection.

if you concat all the small buffer, you will get your
initial buffer.

So you need to configure your initial buffer like that:

'buf' : | size of the big buffer | big buffer |


2/

when you send the 'buf' you will receive several buffers like that


smallbuf1 : | size of the big buffer | small buffer 1 |
smallbuf2 : | small buffer 2 |
smallbuf3 : | small buffer 3 |
...
smallbufN-1 : | small buffer N-1 |
smallbufN : | small buffer N |

if you concat all this small buffer you will get
your initial buffer ('buf')

the first small buffer gives you the size of the data buffer
so concat the next 'size' octet to get your data buffer

I hope you will understant my poor englisk.

--
------------------------------------
Jean-Philippe HILAIRE
jphi...@multimania.com
------------------------------------
Luke Grews <du...@mweb.co.za> a écrit dans le message :
77df05$oa...@forums.borland.com...

Peter Baars

unread,
Jan 17, 1999, 3:00:00 AM1/17/99
to
Hi, if you use sendtext than the maximum length is 8 k exactly. What I do is
split it up in 7.5 kb chunks and keep sending till I am ready. Not nice but it
works...

Peter Baars

Stefan Larsson

unread,
Jan 25, 1999, 3:00:00 AM1/25/99
to
Try to install Winsock 2 if your receiving side is running Win95 (download
from MS site). In NT and Win98 Winsock 2 is already installed. This action
made my large string problem go away. Now I never loose data when sending
single large strings but I did reach another limit. When I tried to send a
textfile line by line the receiving side once again started to loose data. I
belive there is some kind of messages-in-buffer count limit. This problem
could be solved by not using the sendtext method of TWinSocket wich
effectivly ignores any socket error messages. If using something like:

function TDerivedSocket.SendText2(const S: string): Integer;
begin
Result := SendBuf(Pointer(S)^, Length(S));
end;

the result could be checked against SOCKET_ERROR like:

if TDerivedSocket(Socket.Connections[I]).SendText2(Msg) = SOCKET_ERROR then
DoSomething;

If the buffer is full or whatever causes the problem, you could wait a
moment and then try again.

This particulary problem delayed my already optimistic schedule by almost a
week, so I really hope this solves your problem.

Best regards,

Stefan Larsson
Hego System AB

Luke Grews skrev i meddelandet <77df05$oa...@forums.borland.com>...

hgg

unread,
Jan 26, 1999, 3:00:00 AM1/26/99
to
HI
I am using delphi4 in NT4 ,but I still encounter such problem like this:
I use sendtext method of clientsocket to send a string,if the string is
large,
the onclientread() of serversocket will be raised several times,and the
large
string splited into several short string to be received.
if like you say there is some kind of messages-in-buffer count limit,then
how to set the buffer?
need you help.
thanks a lot.

Stefan Larsson wrote in message <78h5kd$pp...@forums.borland.com>...

Stefan Larsson

unread,
Jan 26, 1999, 3:00:00 AM1/26/99
to
As long as your not loosing any data it's probably easy to combine the input
strings to a larger one. Se
http://www.inprise.com/devsupport/delphi/qanda/FAQ2310D.html for more
information.

I don't know if it's possible to mess around with the winsock buffers.

Best regards,

Stefan Larsson
Hego System AB

hgg skrev i meddelandet <78ke3c$sm...@forums.borland.com>...

Bob Whitaker

unread,
Jan 27, 1999, 3:00:00 AM1/27/99
to
I think there is a problem with the ReceiveText method. The problem only occurs
when there is a large message (i.e. greater than 8K) being received via several
packets. Here is an example of the problem...

Given a code snippet within the OnRead event:

MyString := MyServer.ReceiveText;

The problem is this - the length of the string "MyString" is *LONGER* than what
was actually received. I have only seen this happen when Length(MyString) = 8192
(8K). [I discovered this behavior using a tcp/ip sniffer application called
Socket Spy (www.win-tech.com).] Now my app thinks it has received 8192 bytes of
a message, when in reality, it has received less. This throws off the
calculation of how much data I am still expecting to receive. It will eventually
appear as if I am receiving too much data.

Sorry if this post is too off topic for the thread. I mention it in case it
might have some insight on the current problem, and to see if anyone else has
seen this type of behavior. I did come up with a work-around to my problem, but
it is not as simple as just using the ReceiveText method.

Bob

hgg wrote:

> HI
> I am using delphi4 in NT4 ,but I still encounter such problem like this:
> I use sendtext method of clientsocket to send a string,if the string is
> large,
> the onclientread() of serversocket will be raised several times,and the
> large
> string splited into several short string to be received.
> if like you say there is some kind of messages-in-buffer count limit,then
> how to set the buffer?
> need you help.
> thanks a lot.
>

> Stefan Larsson wrote in message <78h5kd$pp...@forums.borland.com>...
> >Try to install Winsock 2 if your receiving side is running Win95 (download
> >from MS site). In NT and Win98 Winsock 2 is already installed. This action
> >made my large string problem go away. Now I never loose data when sending
> >single large strings but I did reach another limit. When I tried to send a
> >textfile line by line the receiving side once again started to loose data.
> I
> >belive there is some kind of messages-in-buffer count limit. This problem
> >could be solved by not using the sendtext method of TWinSocket wich
> >effectivly ignores any socket error messages. If using something like:
> >
> >function TDerivedSocket.SendText2(const S: string): Integer;
> >begin
> > Result := SendBuf(Pointer(S)^, Length(S));
> >end;
> >
> >the result could be checked against SOCKET_ERROR like:
> >
> >if TDerivedSocket(Socket.Connections[I]).SendText2(Msg) = SOCKET_ERROR then
> > DoSomething;
> >
> >If the buffer is full or whatever causes the problem, you could wait a
> >moment and then try again.
> >
> >This particulary problem delayed my already optimistic schedule by almost a
> >week, so I really hope this solves your problem.
> >

> >Best regards,
> >
> >Stefan Larsson
> >Hego System AB
> >

hgg

unread,
Feb 1, 1999, 3:00:00 AM2/1/99
to

HI
> I am using delphi4 in NT4 ,but I still encounter such problem like
this:
>I use sendtext(sendbuf) method of clientsocket to send a string,if the
string is
>large,but just several k,I use receivetext(receivebuf) in the
onclientread() of
serversocket,always lost data happened!
0 new messages