Re: [twsocket] WinSock error 10035 with TWSocketServer

2007-01-17 Thread Dan
 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
 Behalf Of Wilfried Mestdagh
 Sent: 13 January 2007 17:07
 To: twsocket@elists.org
 Subject: Re: [twsocket] WinSock error 10035 with TWSocketServer
 
 Hello Bevan,
 
 I'm not a CBuilder specialis but:
 
AnsiString msg = ((TWSocketClient*) Sender)-ReceiveStr();
 
 This is a good typecast. It tells the compiler that Sender is of type
 TWSocketClient, so compiler can do the exact address offset
 calculations within the type. You still have to check if msg is  .
 

Its ok if you are sure that Sender is a TWSocketClient.  Otherwise its very
unsafe.

TWSocketClient* Client = dynamic_castTWSocketClient*(Sender);
AnsiString msg = Client-ReceiveStr();
 
 The first line will execute, I think the second line will generate an
 exception here. I'm not sure. Did you have it into an exception block ?
 
 As far as I know the dynamic_cast is a kind of equivalent for 'is' or
 'as' operators in Delphi and some other languages. It is not the same as
 a type cast. I even think it will evaluate to false (null) because
 Sender is of type TObject (yeah it is TWSocketClient, but compiler
 dont know that).

A dynamic cast is safer.  Yes its similar to Delphi's as/is operators.  In
this case, this a pointer dynamic cast (rather than a reference), it will
return null/nil if Sender isn't really a TWSocketClient, and the code should
then check for this.  An alternative is to use a reference:

 TWSocketClient Client = dynamic_castTWSocketClient(Sender);

which will throw an exception if Sender isn't a TWSocketClient at runtime.
This is the safest way, it's better to have an exception than to treat an
object as a different class (which could result in memory corruption).

Dan


-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] WinSock error 10035 with TWSocketServer

2007-01-17 Thread bevan
Hi Dan,

 TWSocketClient* Client = dynamic_castTWSocketClient*(Sender);
 AnsiString msg = Client-ReceiveStr();
 
  The first line will execute, I think the second line will generate an
  exception here. I´m not sure. Did you have it into an exception block ?
 
  As far as I know the dynamic_cast is a kind of equivalent for ´is´ or
  ´as´ operators in Delphi and some other languages. It is not the same as
  a type cast. I even think it will evaluate to false (null) because
  Sender is of type TObject (yeah it is TWSocketClient, but compiler
  dont know that).
 
 A dynamic cast is safer.  Yes its similar to Delphi´s as/is operators.  In
 this case, this a pointer dynamic cast (rather than a reference), it will
 return null/nil if Sender isn´t really a TWSocketClient, and the code should
 then check for this.  An alternative is to use a reference:
 
  TWSocketClient Client = dynamic_castTWSocketClient(Sender);

But Sender is a pointer - I didn't think you could typecast a pointer to a 
reference.

Regards,

Bevan





-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Re: [twsocket] WinSock error 10035 with TWSocketServer

2007-01-17 Thread Dan


 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
 Behalf Of [EMAIL PROTECTED]
 Sent: 17 January 2007 22:12
 To: twsocket@elists.org
 Subject: Re: [twsocket] WinSock error 10035 with TWSocketServer
 
 Hi Dan,
 
  TWSocketClient* Client = dynamic_castTWSocketClient*(Sender);
  AnsiString msg = Client-ReceiveStr();
  
   The first line will execute, I think the second line will generate an
   exception here. I4m not sure. Did you have it into an exception block
 ?
  
   As far as I know the dynamic_cast is a kind of equivalent for 4is4 or
   4as4 operators in Delphi and some other languages. It is not the same
 as
   a type cast. I even think it will evaluate to false (null) because
   Sender is of type TObject (yeah it is TWSocketClient, but compiler
   dont know that).
 
  A dynamic cast is safer.  Yes its similar to Delphi4s as/is operators.
 In
  this case, this a pointer dynamic cast (rather than a reference), it
 will
  return null/nil if Sender isn4t really a TWSocketClient, and the code
 should
  then check for this.  An alternative is to use a reference:
 
   TWSocketClient Client = dynamic_castTWSocketClient(Sender);
 
 But Sender is a pointer - I didn't think you could typecast a pointer to a
 reference.
 
 Regards,
 
 Bevan
 

Oops, you're right. *Sender.

Dan


-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] WinSock error 10035 with TWSocketServer

2007-01-13 Thread Wilfried Mestdagh
Hello Bevan,

I'm not a CBuilder specialis but:

   AnsiString msg = ((TWSocketClient*) Sender)-ReceiveStr();

This is a good typecast. It tells the compiler that Sender is of type
TWSocketClient, so compiler can do the exact address offset
calculations within the type. You still have to check if msg is  .

   TWSocketClient* Client = dynamic_castTWSocketClient*(Sender);
   AnsiString msg = Client-ReceiveStr();

The first line will execute, I think the second line will generate an
exception here. I'm not sure. Did you have it into an exception block ?

As far as I know the dynamic_cast is a kind of equivalent for 'is' or
'as' operators in Delphi and some other languages. It is not the same as
a type cast. I even think it will evaluate to false (null) because
Sender is of type TObject (yeah it is TWSocketClient, but compiler
dont know that).

Anyway dont trust my explanation because it is from the back of my head
:)

---
Rgds, Wilfried [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html
http://www.mestdagh.biz

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] WinSock error 10035 with TWSocketServer

2007-01-12 Thread Wilfried Mestdagh
Hello Bevan,

It is normal that you receive an empty string once a while. Just exit
the OnDataAvailable event in that case. When data is really ready to
receive OnDataAvailable will fire again.

About the 10035 yo dont have to worry. This is internally handled by
TWSocket.

---
Rgds, Wilfried [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html
http://www.mestdagh.biz

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] WinSock error 10035 with TWSocketServer

2007-01-12 Thread bevan
Hi Wilfried,

 It is normal that you receive an empty string once a while. Just exit
 the OnDataAvailable event in that case. When data is really ready to
 receive OnDataAvailable will fire again.

I see your point - the other day I got the same result over and over again, 
today the same code works fine.  I'll have to remember to build retry 
functionality into the system :)

BTW, just to clarify what was happening the other day, the following result 
would end up with the variable 'msg' having data:

void __fastcall MyClass::ClientDataAvailable(TObject *Sender, WORD ErrCode)
{
  AnsiString msg = ((TWSocketClient*) Sender)-ReceiveStr();
}

Whereas this code would result in the variable msg being empty:

void __fastcall MyClass::ClientDataAvailable(TObject *Sender, WORD ErrCode)
{
  TWSocketClient* Client = dynamic_castTWSocketClient*(Sender);
  AnsiString msg = Client-ReceiveStr();
}

Regards,

Bevan





-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] WinSock error 10035 with TWSocketServer

2007-01-11 Thread Francois PIETTE
 resulting in an empty string, despite the fact that by inspecting the
 object I could see there is data in the receive buffer.

There is no receive buffer in the component !

 I'm getting error 10035  (operation would block) and
 wondered why this would happen now and not
 previously.

Error 10035 is not really an error when using non blocking socket. It just 
means nothing is ready to be read.
Instead of ReceiveStr, I suggest you use Receive where you have better 
control and is faster since it doesn't involve the memory allocation needed 
for strings.

 Does anyone have any suggestions about what might be going wrong here?

The most common source of probelm is calling the message pump 
(ProcessMessages and the like) directly or indirectly (For example with a 
modal form or a simple ShowMessage).

--
Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html
--
[EMAIL PROTECTED]
http://www.overbyte.be



- Original Message - 
From: Bevan Edwards [EMAIL PROTECTED]
To: ICS support mailing twsocket@elists.org
Sent: Thursday, January 11, 2007 7:28 PM
Subject: [twsocket] WinSock error 10035 with TWSocketServer


 Hi all,

 I am using BDS2006 to write a service application that creates a
 TWSocketServer and waits for connections.  When a connection is made,
 the client sends requests and the service processes the requests and
 returns the results.

 This is all being done with LineMode enabled.

 I've written a similar module in another application recently and that
 went without a hitch.

 In this particular case (using code copied from the other application),
 in OnDataAvailable for the TWSocketClient I type cast the Sender to a
 TWSocketClient and then call ReceiveStr to retrieve the data.  This was
 resulting in an empty string, despite the fact that by inspecting the
 object I could see there is data in the receive buffer.  Further
 investigation/testing has revealed that I'm getting error 10035
 (operation would block) and wondered why this would happen now and not
 previously.

 The only thing I can think of that I'm doing different is that the
 testing is being done on one machine, whereas I don't think I did that
 previously.  However, I have tested this application with the client on
 another machine and it exhibits the same problem.

 Another thing I noticed is that if I do:
  AnsiString msg = ((TWSocketClient*)Sender)-ReceiveStr();
 at the start of the OnDataAvailable event, then I get the data coming
 through.  But I believe (based on the existing application that works)
 that I should be able to typecast the Sender variable first.

 Does anyone have any suggestions about what might be going wrong here?

 Regards,

 Bevan Edwards

 -- 
 To unsubscribe or change your settings for TWSocket mailing list
 please goto http://www.elists.org/mailman/listinfo/twsocket
 Visit our website at http://www.overbyte.be 

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be