TCPClient on Proxy

G

Guest

hi,
I work on a computer that is part of a network and uses proxy to connect to net. I cant connect to servers outside my proxy with simple ConnectTo code. I need to know how to make my requests go through proxy. eg,
_socket = new TcpClient("http://msdn.microsoft.com", port);
does not work.
Thanx.
Ab.
 
G

Guest

Hi Abubakar,

I'm not good i .NET network stuff, but...
The TcpClient constructor needs a "host name"
(e.g. "msdn.microsoft.com"), not a WWW address.

Regards

Marcin
 
M

mphanke

From MSDN:
If your site uses a proxy to provide access to the Internet, you must
configure a proxy instance to enable your application to communicate
with the Web proxy. The following code example creates a global proxy
instance that will enable any WebRequest to use a proxy to
communicate with the Internet. The example assumes that the proxy
server is named webproxy and that it communicates on port 80, the
standard HTTP port.
[C#] WebProxy proxyObject = new WebProxy("http://webproxy:80/");
GlobalProxySelection.Select = proxyObject;
You can override the global proxy selection by assigning an instance
that implements the IWebProxy interface to the Proxy property of your
WebRequest. The following code example sends a WebRequest to
www.contoso.com that overrides the global proxy selection with a
proxy server named alternateproxy on port 80. [C#] WebRequest req =
new WebRequest.Create("http://www.contoso.com/"); req.Proxy = new
WebProxy("http://alternateproxy:80/");

Look at the following topics:

- HTTP
- Accessing the Internet Through a Proxy

Have Fun!

Martin
 
G

Guest

I dont want to use WebRequest,,, I want to use TCPClient.

mphanke said:
From MSDN:
If your site uses a proxy to provide access to the Internet, you must
configure a proxy instance to enable your application to communicate
with the Web proxy. The following code example creates a global proxy
instance that will enable any WebRequest to use a proxy to
communicate with the Internet. The example assumes that the proxy
server is named webproxy and that it communicates on port 80, the
standard HTTP port.
[C#] WebProxy proxyObject = new WebProxy("http://webproxy:80/");
GlobalProxySelection.Select = proxyObject;
You can override the global proxy selection by assigning an instance
that implements the IWebProxy interface to the Proxy property of your
WebRequest. The following code example sends a WebRequest to
www.contoso.com that overrides the global proxy selection with a
proxy server named alternateproxy on port 80. [C#] WebRequest req =
new WebRequest.Create("http://www.contoso.com/"); req.Proxy = new
WebProxy("http://alternateproxy:80/");

Look at the following topics:

- HTTP
- Accessing the Internet Through a Proxy

Have Fun!

Martin
hi,
I work on a computer that is part of a network and uses proxy to connect to net. I cant connect to servers outside my proxy with simple ConnectTo code. I need to know how to make my requests go through proxy. eg,
_socket = new TcpClient("http://msdn.microsoft.com", port);
does not work.
Thanx.
Ab.
 
F

Feroze [msft]

You will have to use TcpClient to connect to your proxy, and send the
correct http request packet to get the data.

However, why do you want to reinvent the wheel ? Why dont you wnat to use
HttpWebRequest ? Remember if you use TcpClient/Socket to do this, you will
also have to parse the returned Http response yourself.

feroze
======================
This posting is provided as-is. It offers no warranties and confers no
rights.


Abubakar said:
hi,
I work on a computer that is part of a network and uses proxy to connect
to net. I cant connect to servers outside my proxy with simple ConnectTo
code. I need to know how to make my requests go through proxy. eg,
 
J

Joerg Jooss

Abubakar said:
here is an example:
I create a simple server, at my *home*, in C# using the Net classes
to listen at some port say P.
I create a client sitting in my *office* (office pc:which uses proxy
for accessing internet) and i want to connect to my home listening
tcp server at IP say X. Now how do I use http, which I dont want here
I guess (i may be wrong), to connect at ip X at port P? Can that be
done with httpwebrequest? Or should it be done with httpwebrequest?

Well, what's the application supposed to be doing? Why implement a custom
protocol on top of TCP/IP? Unless you're doing some really high-endish
stuff, HTTP should do the trick easily.

Cheers,
 
G

Guest

I think I really am not understanding you guys, and now confused because you guys sound so obvious in what you are saying. I need your guidance now. Lets see. I'm on a office network and have to write a program which will connect to an app listening in my home PC on the internet and after connection I just want to send it a message say "hello net!". How do I do this? Just tell me the steps and classes to use.

Ab.
 
J

Joerg Jooss

Abubakar said:
I think I really am not understanding you guys, and now confused
because you guys sound so obvious in what you are saying. I need
your guidance now. Lets see. I'm on a office network and have to
write a program which will connect to an app listening in my home PC
on the internet and after connection I just want to send it a
message say "hello net!". How do I do this? Just tell me the steps
and classes to use.

Well, if all you want to do is get a basic understanding of client/server
network programming, both System.Net.Sockets.Socket and
TcpClient/TcpListener will do the trick. But is this your whole application?
Being able to send a plain text message?

Cheers,
 
G

Guest

now we are getting somewhere.
You see you have mentioned "TcpClient/TcpListener" yourself. I have made pretty nice multiclient, rooms enabled, multi-threaded chat apps before as experiments, so I have the basic understanding of the client-server applications. Now I'v been doing that by using classes that you mentioned which are "TcpClient/TcpListener" and others like networkstream etc. But one of the app that I was trying to make which would enable me to be in contact with my home pc anywhere I go, through my mobile or through a desktop pc. I'm making the desktop version in C# and *will* make the mobile version in Java :( cuz the mobile I got uses a symbian OS and no .net is available for that.
Anyway, so I use the TcpClient to make a connection at an IP say x.x.x.x, but my problem was, due to which i started this thread, that I'm on a network and the ip that I give for connection is alway *not found* or *host unreachable* becuz ofcourse I'm on a network and directly mentioning, inside the network, an IP which is outside the network is not found. So now I needed a way through which my tcplient becomes intelligent enough to automatically resolve that IP through the proxy, but it doesnt.
And in turn everyone started telling me to use httpwebrequest, and I'm like "how does this httwebrequest came into discussion?"
So the question remains.

Ab.
 
S

Sunny

now we are getting somewhere.
You see you have mentioned "TcpClient/TcpListener" yourself. I have made pretty nice multiclient, rooms enabled, multi-threaded chat apps before as experiments, so I have the basic understanding of the client-server applications. Now I'v been doing that by using classes that you mentioned which are "TcpClient/TcpListener" and others like networkstream etc. But one of the app that I was trying to make which would enable me to be in contact with my home pc anywhere I go,
through my mobile or through a desktop pc. I'm making the desktop version in C# and *will* make the mobile version in Java :( cuz the mobile I got uses a symbian OS and no .net is available for that.
Anyway, so I use the TcpClient to make a connection at an IP say x.x.x.x, but my problem was, due to which i started this thread, that I'm on a network and the ip that I give for connection is alway *not found* or *host unreachable* becuz ofcourse I'm on a network and directly mentioning, inside the network, an IP which is outside the network is not found. So now I needed a way through which my tcplient becomes intelligent enough to automatically resolve that IP through the proxy, but it doesnt.
And in turn everyone started telling me to use httpwebrequest, and I'm like "how does this httwebrequest came into discussion?"
So the question remains.

Ab.

Hi,
take a look to the thread with the same name, started by Wal Turner on
Jul 29.

Sunny
 
J

Joerg Jooss

Abubakar said:
now we are getting somewhere.
You see you have mentioned "TcpClient/TcpListener" yourself. I have
made pretty nice multiclient, rooms enabled, multi-threaded chat apps
before as experiments, so I have the basic understanding of the
client-server applications. Now I'v been doing that by using classes
that you mentioned which are "TcpClient/TcpListener" and others like
networkstream etc. But one of the app that I was trying to make which
would enable me to be in contact with my home pc anywhere I go,
through my mobile or through a desktop pc. I'm making the desktop
version in C# and *will* make the mobile version in Java :( cuz the
mobile I got uses a symbian OS and no .net is available for that.

Note: You should post your problem to a networking group, like
comp.os.ms-windows.networking.tcp-ip or
microsoft.public.windowsxp.network_web. This is more a problem of setting up
your infrastructure.
Anyway, so I use the TcpClient to make a connection at an IP say
x.x.x.x, but my problem was, due to which i started this thread, that
I'm on a network and the ip that I give for connection is alway *not
found* or *host unreachable* becuz ofcourse I'm on a network and
directly mentioning, inside the network, an IP which is outside the
network is not found.

So I guess you're talking about a home LAN that is connected to the Internet
by some broadband router performing NAT?
So now I needed a way through which my tcplient
becomes intelligent enough to automatically resolve that IP through
the proxy, but it doesnt.

Your client would talk to the proxy, which in turn talks to the real
application server. A proxy does not resolve addresses for the public. But
anyway, you'll need some network component that is permanently visible on
the Internet, for example by using DynDNS with a compatible router. You
could either expose your server directly (not a good idea) or use a proxy.

Cheers,
 

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