TCPClient on Proxy

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Abubakar

    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.

  • Marcin GrzÄ™bski

    #2
    Re: TCPClient on Proxy

    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
    [color=blue]
    > 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.
    >[/color]

    Comment

    • mphanke

      #3
      Re: TCPClient on Proxy

      From MSDN:
      [color=blue]
      > 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.[/color]
      [color=blue]
      > [C#] WebProxy proxyObject = new WebProxy("http://webproxy:80/");
      > GlobalProxySele ction.Select = proxyObject;[/color]
      [color=blue]
      > 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/");[/color]

      Look at the following topics:

      - HTTP
      - Accessing the Internet Through a Proxy

      Have Fun!

      Martin

      Abubakar wrote:
      [color=blue]
      > 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.
      >[/color]

      Comment

      • Abubakar

        #4
        Re: TCPClient on Proxy

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

        "mphanke" wrote:
        [color=blue]
        > From MSDN:
        >[color=green]
        > > 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.[/color]
        >[color=green]
        > > [C#] WebProxy proxyObject = new WebProxy("http://webproxy:80/");
        > > GlobalProxySele ction.Select = proxyObject;[/color]
        >[color=green]
        > > 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/");[/color]
        >
        > Look at the following topics:
        >
        > - HTTP
        > - Accessing the Internet Through a Proxy
        >
        > Have Fun!
        >
        > Martin
        >
        > Abubakar wrote:
        >[color=green]
        > > 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.
        > >[/color]
        >[/color]

        Comment

        • Feroze [msft]

          #5
          Re: TCPClient on Proxy

          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" <Abubakar@discu ssions.microsof t.com> wrote in message
          news:EB74698E-F326-40C1-9A7A-FE24D0F2A9B6@mi crosoft.com...[color=blue]
          > hi,
          > I work on a computer that is part of a network and uses proxy to connect[/color]
          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,[color=blue]
          > _socket = new TcpClient("http ://msdn.microsoft. com", port);
          > does not work.
          > Thanx.
          > Ab.
          >[/color]


          Comment

          • Joerg Jooss

            #6
            Re: TCPClient on Proxy

            Abubakar wrote:[color=blue]
            > 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?[/color]

            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
            joerg.jooss@gmx .net


            Comment

            • Abubakar

              #7
              Re: TCPClient on Proxy

              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:
              [color=blue]
              > Abubakar wrote:[color=green]
              > > 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?[/color]
              >
              > 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
              > joerg.jooss@gmx .net
              >
              >
              >[/color]

              Comment

              • Joerg Jooss

                #8
                Re: TCPClient on Proxy

                Abubakar wrote:[color=blue]
                > 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.[/color]

                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
                joerg.jooss@gmx .net

                Comment

                • Abubakar

                  #9
                  Re: TCPClient on Proxy

                  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:
                  [color=blue]
                  > Abubakar wrote:[color=green]
                  > > 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.[/color]
                  >
                  > 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
                  > joerg.jooss@gmx .net
                  >
                  >[/color]

                  Comment

                  • Sunny

                    #10
                    Re: TCPClient on Proxy

                    In article <0C8946E0-EFCE-4BB1-A198-E65F34975553@mi crosoft.com>,
                    Abubakar@discus sions.microsoft .com says...[color=blue]
                    > 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,[/color]
                    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.[color=blue]
                    > 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[/color]
                    the proxy, but it doesnt.[color=blue]
                    > 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:
                    >[color=green]
                    > > Abubakar wrote:[color=darkred]
                    > > > 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.[/color]
                    > >
                    > > 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
                    > > joerg.jooss@gmx .net
                    > >
                    > >[/color]
                    >[/color]

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

                    Sunny

                    Comment

                    • Joerg Jooss

                      #11
                      Re: TCPClient on Proxy

                      Abubakar wrote:[color=blue]
                      > 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.[/color]

                      Note: You should post your problem to a networking group, like
                      comp.os.ms-windows.network ing.tcp-ip or
                      microsoft.publi c.windowsxp.net work_web. This is more a problem of setting up
                      your infrastructure.
                      [color=blue]
                      > 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.[/color]

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

                      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,

                      --
                      Joerg Jooss
                      joerg.jooss@gmx .net

                      Comment

                      Working...