Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. TCP Remote Endpoints

TCP Remote Endpoints

Scheduled Pinned Locked Moved C#
csharpjavascriptasp-netcom
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tatham
    wrote on last edited by
    #1

    Hey guys... I am writing an SMTP server and am interested in adding support for open relay blacklists. However, beyond the implementation, what I need to achieve is retrieving the remote IP from the TcpClient object. I know that this can be retrieved from a raw socket object (which can be generated through TcpListenet.AcceptSocket() as opposed to TcpListener.AcceptTcpClient()), although this doesn't support streaming. Any ideas? Tatham Oddie (VB.NET/C#/ASP.NET/VB6/ASP/JavaScript) tatham@e-oddie.com +61 414 275 989

    B 1 Reply Last reply
    0
    • T Tatham

      Hey guys... I am writing an SMTP server and am interested in adding support for open relay blacklists. However, beyond the implementation, what I need to achieve is retrieving the remote IP from the TcpClient object. I know that this can be retrieved from a raw socket object (which can be generated through TcpListenet.AcceptSocket() as opposed to TcpListener.AcceptTcpClient()), although this doesn't support streaming. Any ideas? Tatham Oddie (VB.NET/C#/ASP.NET/VB6/ASP/JavaScript) tatham@e-oddie.com +61 414 275 989

      B Offline
      B Offline
      Blake Coverett
      wrote on last edited by
      #2

      You don't want to use TcpListener at all for another even remotely performant. Stick to Socket.Accept(). -- -Blake (com/bcdev/blake)

      T 1 Reply Last reply
      0
      • B Blake Coverett

        You don't want to use TcpListener at all for another even remotely performant. Stick to Socket.Accept(). -- -Blake (com/bcdev/blake)

        T Offline
        T Offline
        Tatham
        wrote on last edited by
        #3

        Why do you say this? I would have though that something relating to TCP would be best performed by a TcpListener? Is it performance issues, functionality (like what i'm trying to do) or what? Tatham Oddie (VB.NET/C#/ASP.NET/VB6/ASP/JavaScript) tatham@e-oddie.com +61 414 275 989

        B 1 Reply Last reply
        0
        • T Tatham

          Why do you say this? I would have though that something relating to TCP would be best performed by a TcpListener? Is it performance issues, functionality (like what i'm trying to do) or what? Tatham Oddie (VB.NET/C#/ASP.NET/VB6/ASP/JavaScript) tatham@e-oddie.com +61 414 275 989

          B Offline
          B Offline
          Blake Coverett
          wrote on last edited by
          #4

          TcpListener is just a wrapper around Socket. It doesn't give enough flexibility for anything but the most simple applications. Certainly not enough to implement an SMTP server. -- -Blake (com/bcdev/blake)

          T 1 Reply Last reply
          0
          • B Blake Coverett

            TcpListener is just a wrapper around Socket. It doesn't give enough flexibility for anything but the most simple applications. Certainly not enough to implement an SMTP server. -- -Blake (com/bcdev/blake)

            T Offline
            T Offline
            Tatham
            wrote on last edited by
            #5

            Blake Coverett wrote: Certainly not enough to implement an SMTP server. :~ I'll have to debate you on this - the entire serhas has been written and deployed. The only functionality restriction I have discovered was this one problem of determining the remote endpoint. Blake Coverett wrote: It doesn't give enough flexibility for anything but the most simple applications. SMTP, POP3, IMAP and the like are all extremely basic protocols. :doh: For more complex protocol implementations (such as when I implemented the DNS client) I will agree that sockets are more appropriate. Although, I do not value the assosciated coding overheads required to implement the more complex solution when an appropriate wrapper is available. Wrappers are designed to simplfy integration. While I will agree that raw sockets present greater funtionality, I think it is critical that when greater functionality is not required, the appropraite (and probably more reliable) wrapper should be utilised. Anyway, thanks for the help - it certainly spurred some research and did solve the problem. :-D Tatham Oddie (VB.NET/C#/ASP.NET/VB6/ASP/JavaScript) tatham@e-oddie.com +61 414 275 989

            B 1 Reply Last reply
            0
            • T Tatham

              Blake Coverett wrote: Certainly not enough to implement an SMTP server. :~ I'll have to debate you on this - the entire serhas has been written and deployed. The only functionality restriction I have discovered was this one problem of determining the remote endpoint. Blake Coverett wrote: It doesn't give enough flexibility for anything but the most simple applications. SMTP, POP3, IMAP and the like are all extremely basic protocols. :doh: For more complex protocol implementations (such as when I implemented the DNS client) I will agree that sockets are more appropriate. Although, I do not value the assosciated coding overheads required to implement the more complex solution when an appropriate wrapper is available. Wrappers are designed to simplfy integration. While I will agree that raw sockets present greater funtionality, I think it is critical that when greater functionality is not required, the appropraite (and probably more reliable) wrapper should be utilised. Anyway, thanks for the help - it certainly spurred some research and did solve the problem. :-D Tatham Oddie (VB.NET/C#/ASP.NET/VB6/ASP/JavaScript) tatham@e-oddie.com +61 414 275 989

              B Offline
              B Offline
              Blake Coverett
              wrote on last edited by
              #6

              I'm glad to hear the problem is solved. On the merits of TcpListener as a wrapper: If you look through the source for it (isn't Reflector a wonderful tool) you'll see it's all of about 40 lines of code. Really all it does is wrap Bind/Listen in one method and, create TcpClients around accepted sockets, and translate from one set of exceptions to a different set if you try to accept on a closed socket. What does this actually really buy, except hiding the real Socket's based programming model? Perhaps the thought is it buy's having TcpClients rather than sockets after the connect, but they don't add any value in a server scenario at all. The only real abstraction they provide is in the Connect process, which isn't used there. Perhaps what you want is the NetworkStream model for the actual IO. I might argue that too on different grounds, but I won't today. If that's what you want, then then just do a new NetworkStream(listeningSocket.Accept(), true). Of course, better yet is to use the async Socket.BeginAccept/BeginRead/BeginWrite methods. This is where you'll get scalability. regards, -Blake

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups