SSL Socket connections

  • Thread starter Thread starter Alexander Gnauck
  • Start date Start date
A

Alexander Gnauck

Hello,

i must create TCP/IP Connections with SSL. But i have no idea how i can do
this with the Compact Framework. I found only commercial ActiveX controls,
but no .Net controls. Has anybody a idea ?
Is there a way to create a own socket control with PInvoke ? Because the OS
supports SSL.

Thanx Alex
 
Simply use HttpWebRequest (defined in System.Net)

HttpWebRequest req = (HttpWebRequest )WebRequest.Create(new Uri ("https://msdn.one.microsoft.com"));

HttpWebResponse rsp = req.GetResponse() as HttpWebResponse;

foreach( string header in rsp.Headers )
{
listBox1.Items.Add(string.Format("{0}: {1}", header, rsp.Headers[header]));
}

Stream st = rsp.GetResponseStream();
byte[] data = new byte[256];
int cnt = st.Read(data, 0, data.Length);

while (cnt > 0 )
{
string str = Encoding.ASCII.GetString(data, 0, cnt);
textBox1.Text += str;
cnt = st.Read(data, 0, data.Length);
}
 
Hello Alex,

but i dont want to connect to a http Server and i must connect on different ports. Does this also work ?

Alex
Simply use HttpWebRequest (defined in System.Net)

HttpWebRequest req = (HttpWebRequest )WebRequest.Create(new Uri ("https://msdn.one.microsoft.com"));

HttpWebResponse rsp = req.GetResponse() as HttpWebResponse;

foreach( string header in rsp.Headers )
{
listBox1.Items.Add(string.Format("{0}: {1}", header, rsp.Headers[header]));
}

Stream st = rsp.GetResponseStream();
byte[] data = new byte[256];
int cnt = st.Read(data, 0, data.Length);

while (cnt > 0 )
{
string str = Encoding.ASCII.GetString(data, 0, cnt);
textBox1.Text += str;
cnt = st.Read(data, 0, data.Length);
}
 
Good question. Since there is not much in CF along the lines of Cryptography, you will likely need to create your own implementation.
The CF libraries provide internal class SSLSOCK, but it is hidden from the user
Hello Alex,

but i dont want to connect to a http Server and i must connect on different ports. Does this also work ?

Alex
Simply use HttpWebRequest (defined in System.Net)

HttpWebRequest req = (HttpWebRequest )WebRequest.Create(new Uri ("https://msdn.one.microsoft.com"));

HttpWebResponse rsp = req.GetResponse() as HttpWebResponse;

foreach( string header in rsp.Headers )
{
listBox1.Items.Add(string.Format("{0}: {1}", header, rsp.Headers[header]));
}

Stream st = rsp.GetResponseStream();
byte[] data = new byte[256];
int cnt = st.Read(data, 0, data.Length);

while (cnt > 0 )
{
string str = Encoding.ASCII.GetString(data, 0, cnt);
textBox1.Text += str;
cnt = st.Read(data, 0, data.Length);
}
 
Back
Top