Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

secure sockets

7 views
Skip to first unread message

Alexander Gnauck

unread,
Dec 25, 2009, 6:54:08 AM12/25/09
to
I am trying to implement secure sockets using TLs to my application like
described here:
http://msdn.microsoft.com/en-us/library/ms881493.aspx

After the handshake when I am on a secure socket I get always the
following exception: "A blocking operation is currently executing"

I use only asynchronous Read and Write operations. But it looks like the
secure socket API of Windows Mobile supports only 1 operation at a time,
even when using async operations.

This is not good because I am working on an asynchronous protocol and
must be able to receive and send data at any time. It no request
response protocol like HTTP, POP3 and others.

As a workaround I tried to setup a receiver thread with a loop where I
check whether data is available or not before calling BeginReceive. But
this does not work either because socket.Available and FIONREAD both
return always 0, even if data is available in the buffer for reading.

How can I implement asynchronous protocols with the secure socket api?
Any help and pointers are appreciated.

Thanks,
Alex

Paul G. Tobey [ eMVP ]

unread,
Dec 29, 2009, 2:07:01 PM12/29/09
to
Here's what I would suggest: don't use the async calls like BeginReceive.
Instead, use the ordinary blocking WinSock calls like select(), recv(), and
send(). You can still send or receive "at any time", if necessary, by having
a receive thread and a send thread and arranging for each to do whatever it
needs to do asynchronously with the other.

Paul T.

"Alexander Gnauck" wrote:

> .
>

Alexander Gnauck

unread,
Dec 29, 2009, 5:37:33 PM12/29/09
to
Am 29.12.2009 20:07, Paul G. Tobey [eMVP] wrote:
> Here's what I would suggest: don't use the async calls like BeginReceive.
> Instead, use the ordinary blocking WinSock calls like select(), recv(), and
> send(). You can still send or receive "at any time", if necessary, by having
> a receive thread and a send thread and arranging for each to do whatever it
> needs to do asynchronously with the other.

the problem is the receive thread. This thread also calls Receive when
no data is available on the socket. The receive call blocks then until
data was received. While the Receive is blocked I can't call send
because it raised an exception when the socket is SSL or TLS.

Alex

Paul G. Tobey [ eMVP ]

unread,
Dec 29, 2009, 6:26:02 PM12/29/09
to
I don't remember seeing that myself. You can use select() before calling
recv() to verify that there is something to receive, I guess. It's messy,
but it shouldn't break anything that would otherwise work if recv()/send()
worked right for you.

Paul T.

"Alexander Gnauck" wrote:

> .
>

Alexander Gnauck

unread,
Dec 30, 2009, 6:02:24 AM12/30/09
to
Am 30.12.2009 00:26, Paul G. Tobey [eMVP] wrote:
> I don't remember seeing that myself. You can use select() before calling
> recv() to verify that there is something to receive, I guess. It's messy,
> but it shouldn't break anything that would otherwise work if recv()/send()
> worked right for you.

Thanks Paul. The select() works perfect on the SSL socket.

I tried lots of other managed and low level functions before to verify
that I can read on the socket which did not work. Its messy, but works
perfect. I can live with this hack and still hope that the SslStream
class will be available in the next version of the compact framework.

Alex

Paul G. Tobey [ eMVP ]

unread,
Dec 30, 2009, 1:41:01 PM12/30/09
to
> I tried lots of other managed and low level functions before to verify
> that I can read on the socket which did not work. Its messy, but works
> perfect. I can live with this hack and still hope that the SslStream
> class will be available in the next version of the compact framework.
>
> Alex

I'm with you 100% on that. SslStream is dead easy to use by comparison with
raw WinSock.

Paul T.

Sasha K.

unread,
Jan 1, 2010, 11:46:00 PM1/1/10
to
On Dec 25 2009, 6:39 am, Alexander Gnauck <gna...@gmail.com> wrote:
> I am trying to implement secure sockets using TLs to my application like
> described here:http://msdn.microsoft.com/en-us/library/ms881493.aspx
>
> After the handshake when I am on a secure socket I get always the
> following exception: "A blocking operation is currently executing"
>
> I use only asynchronous Read and Write operations. But it looks like the
> secure socket API of Windows Mobile supports only 1 operation at a time,
> even when using async operations.
>
> This is not good  because I am working on an asynchronous protocol and
> must be able to receive and send data at any time. It no request
> response protocol like HTTP, POP3 and others.
>
> As a workaround I tried to setup a receiver thread with a loop where I
> check whether data is available or not before calling BeginReceive. But
> this does not work either because socket.Available and FIONREAD both
> return always 0, even if data is available in the buffer for reading.
>
> How can I implement asynchronous protocols with the secure socket api?
> Any help and pointers are appreciated.
>
> Thanks,
> Alex

While I don't have experience with the native WinCE SSL sockets, I'd
like to point you to http://www.bouncycastle.org/csharp/ which
contains a completely managed implementation of TLS, compatible
with .NET and .NET CF.

0 new messages