Following is my code that I use to connect windows application to my server, But on office machines where limited access to internet, I can not connect i.e. this code fails. I have to use proxy for this. Please help me in writing proxy for following code.
{
TcpClient client = new TcpClient();
client.Connect("98.130.254.199", 0x599);
client.Close();
}
1
Expert's answer
2013-02-27T04:46:08-0500
You can't use proxy with raw sockets (i.e. TcpClient) except creating your own class derived from TcpClient and implementing SOCKS or HTTP proxy support. You'd better use HttpWebRequest/HttpWebResponse pair:
using System.Net; ... HttpWebRequest request = (HttpWebRequest)WebRequest.Create("98.130.254.199"); request.Proxy = new WebProxy("43.59.90.111", 1080); request.Method = "GET";
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { StreamReader reader = new StreamReader(response.GetResponseStream()); Console.WriteLine(reader.ReadToEnd()); ... reader.Close(); response.Close(); }
By the way, the 0x599 or the 1433 port is usually used to connect to the MSSql server, so you should use SqlConnection class to do it.
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment