473,795 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TCPClient on Proxy

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.

Nov 16 '05 #1
10 25140
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
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.

Nov 16 '05 #2
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/");
GlobalProxySele ction.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.Crea te("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

Abubakar wrote:
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.

Nov 16 '05 #3
I dont want to use WebRequest,,, I want to use TCPClient.

"mphanke" wrote:
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/");
GlobalProxySele ction.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.Crea te("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

Abubakar wrote:
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.

Nov 16 '05 #4
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" <Ab******@discu ssions.microsof t.com> wrote in message
news:EB******** *************** ***********@mic rosoft.com...
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.

Nov 16 '05 #5
Abubakar wrote:
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,

--
Joerg Jooss
jo*********@gmx .net
Nov 16 '05 #6
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.
"Joerg Jooss" wrote:
Abubakar wrote:
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,

--
Joerg Jooss
jo*********@gmx .net

Nov 16 '05 #7
Abubakar wrote:
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.Sock ets.Socket and
TcpClient/TcpListener will do the trick. But is this your whole application?
Being able to send a plain text message?

Cheers,
--
Joerg Jooss
jo*********@gmx .net

Nov 16 '05 #8
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.

"Joerg Jooss" wrote:
Abubakar wrote:
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.Sock ets.Socket and
TcpClient/TcpListener will do the trick. But is this your whole application?
Being able to send a plain text message?

Cheers,
--
Joerg Jooss
jo*********@gmx .net

Nov 16 '05 #9
In article <0C************ *************** *******@microso ft.com>,
Ab******@discus sions.microsoft .com says...
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.

"Joerg Jooss" wrote:
Abubakar wrote:
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.Sock ets.Socket and
TcpClient/TcpListener will do the trick. But is this your whole application?
Being able to send a plain text message?

Cheers,
--
Joerg Jooss
jo*********@gmx .net


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

Sunny
Nov 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3050
by: מורדי | last post by:
Hi, I'm writing a client/server application in which the client send a series of screenshots to the server to be saved using the tcpclient. in most cases the first screenshot is transmitted ok and arrives at the server but from after that i only a couple of KB from the start of the file which cases the picture to display only the very top (of the screen). All the pictures are saved at the client side before sent to the server and they...
5
6146
by: Wal Turner | last post by:
This has been discussed in a prior thread but there was no solution proposed. Also, using WebRequest is not viable since we need a keep-alive connection. Can anyone provide any information on using the TCPClient class (or other) via proxies and whether or not this is possible? Regards Wwal
0
1637
by: Evan Freeman[C++ Samuri] | last post by:
Recently I found a question online that originated from this group, and those who responded to it were of no help to the poster. So I am sorry that I was not watching this group before, but will from now on and will offer my help as follows to anser the original question. **************************************************************************** ******************************************* hi, I work on a computer that is part of a...
4
4477
by: WATYF1 | last post by:
Hello. I'm writing a VB.NET app to check email message counts for both POP3 and IMAP4. I'm using TCPClient to connect, and a NetworkStream to send simple commands. It's a very simple bit of code, actually... the problem is, if the user is behind a proxy, then the Connect method fails (times out). How do I get around this? I thought this would be a common issue and that there would be plenty of code out there to demonstrate how to...
5
2748
by: Jim W | last post by:
I have an ASP.NET app that has very slow connect times using TCPClient, or the Socket class, or even calling a COM object that uses C socket calls on certain similar XP SP2 boxes. On those boxes, if another connection is made within a couple seconds, it is fast. Running the same C# code in a console app connects instantly. Unplugging the network cable allows localhost connections to be instant (?!). Running the same ASP.NET app on...
0
1362
by: Tamas Bojcan | last post by:
Hi, I use TcpClient class to obtain a NetworkStream object (via TcpClient's GetStream() method) in an ASP.Net webapp. This works well if I'm not behind proxy server but if I'm connected to the network via proxy server I get "dead network..." error message during the creation of the TcpClient object. The most strange thing is that the same code is works well with proxy too if it is in a single C# project. What's the problem in case of...
6
5724
by: Julien | last post by:
Hi, I am developing a C# application to send requests to mail server to check email addresses validity. I use a TcpClient object to connect to it with the Connect(String hostname, Int32 port) method. When I use my application at home I don't have any problem to connect and get responses but when I try at work, I get the SocketException number 10061 : "target machine actively refused it". I don't have any proxy, maybe a firewall.
0
1575
by: aladdinm1 | last post by:
Dear all, I have a client application which working just fine except in one case: when it's behind a proxy. I tested it behind MS ISA with enabled Socks service. I tried everything to make it connect from behind the proxy but, it failed. I'm using .Net Framework 2.0 and it looks like it does not support Socks proxies. Is there any solution for this problem? Thanks in advance.
4
9173
by: Peter | last post by:
Hi I rewrite an old C Programm to C# (Framework 1.1) - it is an easy FTP- Client. I create a "Command-Channel" using TcpClient, a "Command-Reader" and a "Command-Writer" to speak with the FTP Server coChannel = new TcpClient(this.HostName, this.Port); coReader = new StreamReader(coChannel.GetStream());
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10214
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7540
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.