🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
5 messages
5 total messages Started by Guenter Stubbe Mon, 06 Jun 2005 16:12
TWinSocketStream->Write / Read questions
#3847
Author: Guenter Stubbe
Date: Mon, 06 Jun 2005 16:12
23 lines
1839 bytes
Hi all,

I have questions according to the usage of TWinSocketStream.
If I call the Write method two or more times successively, not all data 
is transfered (in my application). If I code a Sleep(50) between them, 
the transfer works. Why? What is a good value for the Sleep?

The Read method of TWinSocketStream can return a "-1"?
I have read different answers in this newgroup: 23 Dec 2004, answer to 
Niyazi Unugur: "Read never returns -1. ..."

6 Apr 2005, answer to Paul: " ... You are not taking into account that 
Read can return -1 if an error occurs."

In the german help there is a hint, that the WaitForData method should 
be called always, if a Read or Write method is called afterwards:
In my code, the WaitForData only works for the Read method...

What is a usual size for packets written or read via TWinSocketStream?
I have no idea and need a starting point.

Thanks in advance
	Guenter
Re: TWinSocketStream->Write / Read questions
#3848
Author: Remy Lebeau (TeamB)
Date: Mon, 06 Jun 2005 17:01
30 lines
1913 bytes
"Guenter Stubbe" <no-spam@no.spam.com> wrote in message
news:42a475d3$1@newsgroups.borland.com...

> If I call the Write method two or more times successively, not
> all data is transfered (in my application). If I code a Sleep(50)
> between them, the transfer works.

I have never had to use Sleep() with TWinSocketStream.  Successive
reads/writes without sleeping has always worked fine for me without problem.
Please show your actual code.

> The Read method of TWinSocketStream can return a "-1"?

The only way for Read() to return -1 is if a socket error occured.  But if
that happened, you should be getting a ESocketError exception as well.

> In the german help there is a hint, that the WaitForData method
> should be called always, if a Read or Write method is called
> afterwards: In my code, the WaitForData only works for the Read
> method...

That is correct.  The help is wrong.

> What is a usual size for packets written or read via TWinSocketStream?

Makes no difference.


Gambit
Re: TWinSocketStream->Write / Read questions
#3849
Author: Bob Gonder
Date: Mon, 06 Jun 2005 17:04
28 lines
2223 bytes
Guenter Stubbe wrote:

>I have questions according to the usage of TWinSocketStream.
>If I call the Write method two or more times successively, not all data 
>is transfered (in my application). If I code a Sleep(50) between them, 
>the transfer works. Why? What is a good value for the Sleep?

What timeout value are you giving Write, and how big is your buffer,
and how fast is your connection ?
See the TimeOut property.

>In the german help there is a hint, that the WaitForData method should 
>be called always, if a Read or Write method is called afterwards:

Yes, should do so. It doesn't sound like Wait waits for write
completion (Write does that), just waits for the socket to be ready to
send.

>What is a usual size for packets written or read via TWinSocketStream?
>I have no idea and need a starting point.

What's best depends on your connection speed.
I would probably set the buffer size to 1/2 the timeout value, or the
timeout to twice the max buffer size (as adjusted by the expected
connection rate). And, again, as adjusted by human factors. I don't
want the timeout so large that the user thinks I locked up. And, I
don't want the timeout so small that the user can't possibly notice
it.
Re: TWinSocketStream->Write / Read questions
#3855
Author: Guenter Stubbe
Date: Wed, 08 Jun 2005 08:49
10 lines
1392 bytes
Remy Lebeau (TeamB) schrieb:
...
> I have never had to use Sleep() with TWinSocketStream.  Successive
> reads/writes without sleeping has always worked fine for me without problem.
> Please show your actual code.

With the knowledge, that the Sleep is not needed I have detected the 
error in my application.

Thank you very much for your answers.
Re: TWinSocketStream->Write / Read questions
#3856
Author: Guenter Stubbe
Date: Wed, 08 Jun 2005 09:05
53 lines
2657 bytes


Bob Gonder schrieb:
> Guenter Stubbe wrote:
> 
> 
>>I have questions according to the usage of TWinSocketStream.
>>If I call the Write method two or more times successively, not all data 
>>is transfered (in my application). If I code a Sleep(50) between them, 
>>the transfer works. Why? What is a good value for the Sleep?
> 
> 
> What timeout value are you giving Write, and how big is your buffer,
> and how fast is your connection ?
> See the TimeOut property.
> 

The first question is obsolete, becaus with the hint from Remy Lebeau I 
found the Write works without the Sleep. I have made an error in parsing 
the buffer ...

> 
>>In the german help there is a hint, that the WaitForData method should 
>>be called always, if a Read or Write method is called afterwards:
> 
> 
> Yes, should do so. It doesn't sound like Wait waits for write
> completion (Write does that), just waits for the socket to be ready to
> send.
> 
> 

Ok.


>>What is a usual size for packets written or read via TWinSocketStream?
>>I have no idea and need a starting point.
> 
> 
> What's best depends on your connection speed.
> I would probably set the buffer size to 1/2 the timeout value, or the
> timeout to twice the max buffer size (as adjusted by the expected
> connection rate). And, again, as adjusted by human factors. I don't
> want the timeout so large that the user thinks I locked up. And, I
> don't want the timeout so small that the user can't possibly notice
> it.
> 


I expect the size of the buffer is in byte and the timeout value in ms.

Thank you very much for your help.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads