EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Two problems with ElClientSSLSocket

Posted: 07/31/2007 15:25:32
by Quido Evers (Basic support level)
Joined: 07/23/2007
Posts: 9


I'm trying to create a Windows Mobile 5 application (.NET CF 2.0) with Visual Studio Orcas (Beta 1). But I'm having some difficulty using your components.

First the code (I have removed some irrelevant code, so it might not compiler in this form):

namespace SSLSocketTester
  public partial class TesterForm : Form
    private byte[] receiveBuf = new byte[1024];
    private ElClientSSLSocket sslClient;
    private Socket transport;
    private IPAddress hostaddr;
    private IPEndPoint epHost;

    private void sslClientCertificateValidate(Object sender, SBX509.TElX509Certificate certificate, ref bool validate)
      // For now, accept all certificates
      validate = true;

    private void sslClientCertificateNeededEx(object Sender, ref TElX509Certificate Certificate)
      // Do nothing

    private void sslClient_OnError(object Sender, int ErrorCode, bool Fatal, bool Remote)
      // Reports the error to a control on the form
      // ...
      // ...

    private void TesterForm_Load(object sender, EventArgs e)
      sslClient = new ElClientSSLSocket();
      sslClient.OnCertificateValidate += new SBSSLCommon.TSBCertificateValidateEvent(sslClientCertificateValidate);
      sslClient.OnCertificateNeededEx += new SBClient.TSBCertificateNeededExEvent(sslClientCertificateNeededEx);
      sslClient.OnError += new SBSSLCommon.TSBErrorEvent(sslClient_OnError);

      transport = new Socket(AddressFamily.InterNetwork,
        SocketType.Stream, ProtocolType.Tcp);
      sslClient.Socket = transport;

    private void btnConnect_Click(object sender, EventArgs e)
        // I have tried declaring these variables here
        hostaddr = Dns.GetHostEntry("").AddressList[0];
        epHost = new IPEndPoint(hostaddr, 443);

        sslClient.SSLEnabled = true;
        // TLS is not supported by my server.
        // If I turn it on, an SSL 75778 error occurs
        sslClient.Versions = SBConstants.Unit.sbSSL2 | SBConstants.Unit.sbSSL3;

        if (sslClient.Connected)
          String request = "GET /Alive HTTP/1.1\r\n" +
                           "Host:\r\n" +
                           "Connection: keep-alive\r\n" +
                           "User-Agent: My Client\r\n\r\n";

          // A delay, even of 4 seconds, doesn't have any influance (good or bad)
          if (ckbSleep.Checked)

          int len = sslClient.Receive(receiveBuf, receiveBuf.Length, 0);

          // This response is an zero-length string
          String s = Encoding.Default.GetString(receiveBuf, 0, len);
          // Receive again
          len = sslClient.Receive(receiveBuf, receiveBuf.Length, 0);

          // This response is correct and contains the data I expect
          s = Encoding.Default.GetString(receiveBuf, 0, len);
      catch (System.Net.Sockets.SocketException ex)
        // Reset the connection
        if (sslClient.Connected)
    private void btnDisconnect_Click(object sender, EventArgs e)
      if (sslClient.Connected)

There are 2 problems with this code. First, you might notice that I call sslClient.Receive twice, directly after each other. This is because the first call always returns 0 bytes of response on my custom server. This might be a problem specific to my server, but I think there's no problem there, because another client (written in Delphi with OpenSSL components, as is the server) can connect properly.
Do you see what's wrong?

Second, ultimately I want to create a keep-alive connection. Connect once, send a GET request, receive the response, send a request, receive, etc... and disconnect. Therefore I separated the sslClient.Close() into a separate function (an OnClick handler). When I click the connect button the first time, a connection is made and a response is received. But when I click the disconnect button and then the connect button again, an ObjectDisposedException occurs with the following message:
"System.Net.Sockets.Socket" on sslClient.Connect(epHost).

I'm relatively new to C# so there might be a problem with scoping, garbage collection, etc.

Thank you for you help,

Quido Evers

PS: your samples could be much better if you included some comments in them, explaining why you do certain steps.
E.g. why do you always close a connection using Close(true). According to the documentation this doesn't let the server know you close the connection, which doesn't seem the proper thing to do. Isn't it better to let the server know?
Posted: 08/01/2007 01:56:42
by Eugene Mayevski (Team)

I think it would be much easier if you could send us your test case. We would need to create one so having yours will speed-up processing of your request. Please use HelpDesk ( http://www.eldos.com/support/ticket_list.php ) to post the sample.

Sincerely yours
Eugene Mayevski



Topic viewed 1880 times

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


Back to top

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

Got it!