EldoS | Feel safer!

Software components for data protection, secure storage and transfer

ElClientSSLSocket and (T)ElClientSocket

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#3930
Posted: 10/03/2007 04:52:03
by Quido Evers (Basic support level)
Joined: 07/23/2007
Posts: 9

Finally... some time to complete the evaluation of your components :D I have made some progress since [url=http://www.eldos.com/forum/read.php?FID=7&TID=660]my previous post[/url]. Most problems appeared to be caused by Visual Studio Orcas. I'm back to VS2005 now...

But I still have some questions on how to use your components. The samples and the help did not answer all my questions. The questions I would like to be answered are underlined).

Here's my situation:
I send a request to a server and the server responds with an "infinite" stream of data. After processing the first chunk of data, I want to wait until the
next data comes in, over the same connection.

In response to my previous post you recommended to use either ElClientSSLSocket or ElHTTPSClient (I chose the ElClientSSLSocket because of the infinite stream of data). The Chat sample uses TElSecureClient, which is not documented. In the documentation I found another class called ElSecureClient. What is the difference (in usage and in function) between the ElClientSSLSocket and TElSecureClient? And what about ElSecureClient?

In the chat sample BeginReceive is called on the transport (TElSecureClient.Socket), but in the ElClientSSLSocket sample the Receive is called directly on ElClientSSLSocket, although a Socket property is available on ElClientSSLSocket. Should I call ElClientSSLSocket.BeginReceive or ElClientSSLSocket.Socket.BeginReceive and what should I pass as AsyncState parameter? Do you have a async receive sample for ElClientSSLSocket?

I tried the following:
After sending the request (synchronously) I call BeginReceive on ElClientSSLSocket:

Code
   ElClientSSLSocket sslSocket;
  
   sslSocket = new ElClientSSLSocket();
   sslSocket.OnCertificateValidate += new
     SBSSLCommon.TSBCertificateValidateEvent(sslClientCertificateValidate);
   sslSocket.OnCertificateNeededEx += new
     SBClient.TSBCertificateNeededExEvent(sslClientCertificateNeededEx);
   sslSocket.OnError += new SBSSLCommon.TSBErrorEvent(sslClient_OnError);
  
   transport = new Socket(AddressFamily.InterNetwork,
     SocketType.Stream, ProtocolType.Tcp);
   sslSocket.Socket = transport;
  
   sslSocket.SSLEnabled = false;
   sslSocket.Versions = SBConstants.Unit.sbSSL2 | SBConstants.Unit.sbSSL3;
  
   epHost = GetEndPoint(); // Gets a valid IPEndPoint
  
   sslSocket.Connect(epHost);
   if (sslSocket.Connected)
   {
     sslSocket.Send(Encoding.ASCII.GetBytes(request));
  
     sslSocket.BeginReceive(receiveBuf, 0, receiveBuf.Length,
       new AsyncCallback(OnReceiveCallback), sslSocket);
   }


Receive buf is an instance field (byte[]) and has been allocated (1024 byte)

OnReceiveCallback contains this code:

Code
   ElClientSSLSocket sslClient = null;

   sslClient = (ElClientSSLSocket)ar.AsyncState;
   int len = sslClient.EndReceive(ar);
      
   // parsing receiveBuf and processing the parsed data, works fine
      
   sslClient.BeginReceive(receiveBuf, 0, receiveBuf.Length,
     new AsyncCallback(OnReceiveCallback), sslClient);


This works fine for the first chunk of data. The callback is executed (once) and the first chunk is processed correctly. The call to BeginReceive (in de callback) seems to have no effect though. More data is sent by the server (Ethereal shows loads of packages) but the callback is never called again.
What am I missing here...

Thanks for you help...

Quido Evers



PS: you should really consider to add some comments to the code in the samples. I didn't find one line of comment in your samples (except for the comments Visual Studio automatically generates). The help would benefit from an overview of when to use which component.
#3931
Posted: 10/03/2007 05:17:21
by Eugene Mayevski (EldoS Corp.)

Quote
Quido Evers wrote:
What is the difference (in usage and in function) between the ElClientSSLSocket and TElSecureClient? And what about ElSecureClient?


ElClientSSLSocket, as it name says, is a client-side socket with SSL capabilities.
ElSecureClient (with or without T) is a pure SSL layer which works with any data carrier.

Quote
Quido Evers wrote:
What am I missing here...


The fact that you can't call BeginReceive in the callback. Refer to MSDN documentation for information about asynchronous sockets and their behaviour.



Sincerely yours
Eugene Mayevski
#3932
Posted: 10/03/2007 06:27:33
by Quido Evers (Basic support level)
Joined: 07/23/2007
Posts: 9

Quote
Eugene Mayevski wrote:
ElClientSSLSocket, as it name says, is a client-side socket with SSL capabilities.
ElSecureClient (with or without T) is a pure SSL layer which works with any data carrier.


Why does ElClientSSLSocket have a Socket property, if it is a socket itself? And what should / can I use it for?

Quote
Eugene Mayevski wrote:
ElSecureClient (with or without T)


So ElSecureClient and TElSecureClient are synonyms?

Quote
Eugene Mayevski wrote:
The fact that you can't call BeginReceive in the callback.


Then why do you call BeginReceive in the AsyncReceiveCallback method in your Chat sample (MainClientWnd.cs)? And how can I receive the next data that has been sent by the server?

Quote
Eugene Mayevski wrote:
Refer to MSDN documentation for information about asynchronous sockets and their behaviour.


So the BeginReceive on your components is just passing all the arguments to the underlying raw socket?

Thanks for the quick response..

Quido Evers
#3933
Posted: 10/03/2007 06:46:54
by Quido Evers (Basic support level)
Joined: 07/23/2007
Posts: 9

Quote
Eugene Mayevski wrote:
The fact that you can't call BeginReceive in the callback.


Then why do you call BeginReceive in the AsyncReceiveCallback method in your Chat sample (MainClientWnd.cs)? And how can I receive the next data that has been sent by the server?

Quote
Eugene Mayevski wrote:
Refer to MSDN documentation for information about asynchronous sockets and their behaviour.


MSDN provides [url=http://msdn2.microsoft.com/en-us/library/bbx2eya8.aspx]this[/url] sample and they call BeginReceive in the callback...

Grtz,

Q.
#3934
Posted: 10/03/2007 06:49:36
by Eugene Mayevski (EldoS Corp.)

The samples are not always perfect. I'd recommend using synchronous methods cause they don't spawn secondary threads. Use Available property to check if you have anything to read.


Sincerely yours
Eugene Mayevski
#3935
Posted: 10/03/2007 07:10:45
by Quido Evers (Basic support level)
Joined: 07/23/2007
Posts: 9

Quote
Eugene Mayevski wrote:
The samples are not always perfect.


They should at least work....

I found several samples on the web that call a BeginReceive from within a callback. I find it a bit hard to believe that all these sources publish samples with exactly the same design error in it.

Quote
Eugene Mayevski wrote:
I'd recommend using synchronous methods cause they don't spawn secondary threads. Use Available property to check if you have anything to read.


First, I can't block my application when receiving data. Therefore there has to be a second thread that waits for the data. Using synchronous methods just because they don't spawn threads is not really convincing. I'd rather have someone else (you) write the threading code.

Second, why are there asynchronous methods available in your components, if you recommend not to use them? This is not really assuring when evaluating your components. Are there any more features I shouldn't use?

Grtz,

Q.
#3936
Posted: 10/03/2007 07:22:17
by Eugene Mayevski (EldoS Corp.)

The question "why" is answered only for customers with Standard and Advanced support. Unregistered customers only get basic support. It includes only answering basic technical questions which can appear during evaluation of the product.


Sincerely yours
Eugene Mayevski
Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.

Reply

Statistics

Topic viewed 2763 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!