SSL Socket connections

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
 
A

Alex Feinman [MVP]

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);
}
 
A

Alexander Gnauck

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);
}
 
A

Alex Feinman [MVP]

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);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top