Page 1 of 1

Third part socket connection

Posted: Wed Aug 31, 2011 8:51 pm
by dmunroe
I'm trying to connect to my station from a service that I am creating. I want to store the data, in a SQL database for reporting and analysis.

I've configured my router to forward ports 7777, 5558, and 5559. On any of these ports, I can connect and view the data via a web browser. However, when I connect via a socket from a C# application, I either get a timeout, rejected by the host, or nothing at all.

I've tried the following various GET strings to receive the data, but nothing seems to work:

string Get = "GET http://MyIPAddress:7777/meteolog.cgi?type=xml&mode=data";
string Get = "GET http://MyIPAddress HTTP/1.1";
string Get = "GET MyIPAddress:7777/meteolog.cgi?type=xml&mode=data HTTP/1.1";
string Get = "GET http://MyIPAddress HTTP/1.1";
string Get = "GET MyIPAddress:7777 HTTP/1.1\r\nHost: /meteolog.cgi?type=xml&mode=data";

Any help would be greatly appreciated. Thank you.

Re: Third party socket connection

Posted: Sat Sep 24, 2011 3:52 am
by dmunroe
I was able to finally figure out how to access this data from C# code. I'm posting the solution here, for use by others with similiar issues. I chose not to use XML for simplicity:

using (WebClient client = new WebClient())
//manipulate request headers (optional)
client.Headers.Add(HttpRequestHeader.UserAgent, "text/plain");

using (StreamReader reader = new StreamReader(client.OpenRead(http://YOURIPADDRESS:YOUROPENPORT/meteolog.cgi?mode=data)))
string s = reader.ReadToEnd();

string[] lines = s.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);