76 327
Assignments Done
Successfully Done
In May 2019

Answer to Question #25212 in C# for harshal

Question #25212
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("", 0x599);
Expert's answer
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("");
request.Proxy = new WebProxy("", 1080);
request.Method = "GET";

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
StreamReader reader = new StreamReader(response.GetResponseStream());

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.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions