Is c++ StreamSocket::ConnectAsync working?
-
Monday, September 24, 2012 11:20 PM
I tried to connect to a server using StreamSocket. C++ ConnectAsync stays in Starting status. I tried on c# version, it connects without any problem.
I couldn't find any example or discussion on using C++ StreamSocket as a client. Is anybody using c++ version without problem?
All Replies
-
Monday, September 24, 2012 11:29 PMModerator
It should work fine. Take a look at the StreamSocket sample for an example.
If you still have problems with this then please post a more specific question with details about how you are calling it, the behavior that you expect, and the actual behavior that you get.
--Rob
-
Tuesday, September 25, 2012 12:07 AM
The sample is for server side, not client side.
My code is like this:
StreamSocket ^socket = ref new StreamSocket();
HostName ^host = ref new HostName(ref new Platform::String(L"address here"));
task <void>(socket->ConnectAsync(host, L"port here", SocketProtectionLevel::Ssl)).then([this](task<void> previousTask)
{
// my process block
});
but it never goes into the "my process block". So I tried to check the connect status by:
IAsyncAction ^act = socket->ConnectAsync(host, L"port here", SocketProtectionLevel::Ssl);
while(act->Status != AsyncStatus::Completed)
{
OutputDebugString(act->Status.ToString()->Data);
}
It always prints out "Started".
-
Tuesday, September 25, 2012 12:11 AM
Same code in c# works fine
-
Tuesday, September 25, 2012 2:21 AM
Please try using SocketProtectionLevel::PlainSocket.
You can only use SSL/TLS connection with StreamSocket object as the client in the SSL/TLS negotiation. SSL/TLS cannot currently be used by the StreamSocketListener with the StreamSocket created when a connection is received to enable SSL/TLS on the StreamSocket created, since the SSL/TLS negotiation as a server is not implemented for a StreamSocket. The client support for SSL/TLS does not include the ability to use client certificates.
Please follow the proper step in both client and server side like StreamSocket sample and Secure socket connections with TLS/SSL.
- Edited by Mokarrom Hossain Tuesday, September 25, 2012 2:39 AM
-
Tuesday, September 25, 2012 5:15 PMI am confused. I am not writing server side code. My app is on client side. The server supports ssl. And the c# code with ssl connection can connect to the server without problem.
-
Wednesday, September 26, 2012 12:05 AMModerator
If you look at a network trace (Netmon or Wireshark for example) how far is the socket negotiation progressing? Is the TCP 3 way handshake completing? Is the SSL handshake started or completing?
David Lamb
- Edited by DavidLambMicrosoft Employee, Moderator Wednesday, September 26, 2012 12:07 AM
- Proposed As Answer by Jesse JiangMicrosoft Contingent Staff, Moderator Monday, October 01, 2012 6:00 AM


