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
Voice Data Systems Inc.
360-686-8315
Luke Grews wrote in message <77df05$oa...@forums.borland.com>...
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
I did a search on 'TClient' & limited my search to Delphi...
Cheers,
Cyd
Bob Whitaker wrote in message <369B539B...@ornl.gov>...
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
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>...
Stefan Larsson wrote in message <78h5kd$pp...@forums.borland.com>...
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>...
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
> >