Web Request Crashes If Not Port 80

G

George Shubin

I have a handheld running Windows Mobile 5 and an electronic scale with a WiFi connection at a fixed IP address. When the scale is used, a value is streamed to port 2101. I need to suck data off an that port. When I run the following code, address "http://192.168.1.107/" works just fine, but it grabs the built-in admin login web page. When I use "http://192.168.1.107:2101/", the code crashes with "This protocol is not supported".

Running Compact Framework 2, how do I code for a port that is not 80?

Dim httpResponse As HttpWebResponse
Dim ipAddress As String = "http://192.168.1.107/"
'Dim ipAddress As String = "http://192.168.1.107:2101/"
Dim httpRequest As HttpWebRequest = CType(WebRequest.Create(ipAddress), HttpWebRequest)

httpRequest.Credentials = CredentialCache.DefaultCredentials
httpResponse = CType(httpRequest.GetResponse, HttpWebResponse)


Thanks for any suggestions.

GS
 
P

Peter Foot

Sounds to me like you need to open a Socket on that port (or use TcpClient) and read the data stream, not use a HTTP request e.g.

TcpClient t = new TcpClient();
t.Connect(IPAddress.Parse("192.168.1.107"), 2101);
Stream s = t.GetStream();

//read values from stream

t.Close();

Peter

--
Peter Foot
Microsoft Device Application Development MVP
peterfoot.net | appamundi.com | inthehand.com
APPA Mundi Ltd - Software Solutions for a Mobile World
In The Hand Ltd - .NET Components for Mobility

I have a handheld running Windows Mobile 5 and an electronic scale with a WiFi connection at a fixed IP address. When the scale is used, a value is streamed to port 2101. I need to suck data off an that port. When I run the following code, address "http://192.168.1.107/" works just fine, but it grabs the built-in admin login web page. When I use "http://192.168.1.107:2101/", the code crashes with "This protocol is not supported".

Running Compact Framework 2, how do I code for a port that is not 80?

Dim httpResponse As HttpWebResponse
Dim ipAddress As String = "http://192.168.1.107/"
'Dim ipAddress As String = "http://192.168.1.107:2101/"
Dim httpRequest As HttpWebRequest = CType(WebRequest.Create(ipAddress), HttpWebRequest)

httpRequest.Credentials = CredentialCache.DefaultCredentials
httpResponse = CType(httpRequest.GetResponse, HttpWebResponse)


Thanks for any suggestions.

GS
 
G

George Shubin

Thanks, Peter. I'll tinker with that approach. For me, all this TCIP programming is uncharted waters, so I really appreciate the help.

GS
Sounds to me like you need to open a Socket on that port (or use TcpClient) and read the data stream, not use a HTTP request e.g.

TcpClient t = new TcpClient();
t.Connect(IPAddress.Parse("192.168.1.107"), 2101);
Stream s = t.GetStream();

//read values from stream

t.Close();

Peter

--
Peter Foot
Microsoft Device Application Development MVP
peterfoot.net | appamundi.com | inthehand.com
APPA Mundi Ltd - Software Solutions for a Mobile World
In The Hand Ltd - .NET Components for Mobility

I have a handheld running Windows Mobile 5 and an electronic scale with a WiFi connection at a fixed IP address. When the scale is used, a value is streamed to port 2101. I need to suck data off an that port. When I run the following code, address "http://192.168.1.107/" works just fine, but it grabs the built-in admin login web page. When I use "http://192.168.1.107:2101/", the code crashes with "This protocol is not supported".

Running Compact Framework 2, how do I code for a port that is not 80?

Dim httpResponse As HttpWebResponse
Dim ipAddress As String = "http://192.168.1.107/"
'Dim ipAddress As String = "http://192.168.1.107:2101/"
Dim httpRequest As HttpWebRequest = CType(WebRequest.Create(ipAddress), HttpWebRequest)

httpRequest.Credentials = CredentialCache.DefaultCredentials
httpResponse = CType(httpRequest.GetResponse, HttpWebResponse)


Thanks for any suggestions.

GS
 

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