Multiple listeners on a TCP/IP port?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul A. Steckler

    Multiple listeners on a TCP/IP port?

    I need to write a TCP/IP server in C# that can handle multiple connections.
    My first try was to use TCPListener instances in multiple .NET threads.
    Of course, I got an exception from System.Net.Sock ets about multiple
    sockets on the same port. This happens even with a single listener in
    multiple
    Win32 processes.

    Will I get better results by using a Socket instance with BeginAccept?
    Should I run multiple threads, or do the asynchronous callbacks already
    give me enough concurrency?

    -- Paul


  • Tom Shelton

    #2
    Re: Multiple listeners on a TCP/IP port?

    On 2003-11-26, Paul A. Steckler <steck@acm.or g> wrote:[color=blue]
    > I need to write a TCP/IP server in C# that can handle multiple connections.
    > My first try was to use TCPListener instances in multiple .NET threads.
    > Of course, I got an exception from System.Net.Sock ets about multiple
    > sockets on the same port. This happens even with a single listener in
    > multiple
    > Win32 processes.
    >
    > Will I get better results by using a Socket instance with BeginAccept?
    > Should I run multiple threads, or do the asynchronous callbacks already
    > give me enough concurrency?
    >
    > -- Paul
    >
    >[/color]

    My personal preference is to use a Socket instance and the async methods
    - but, your problem is caused by a misuse of the TCPListener class. You
    only need one instace of the TCPListener class. You accept connections
    using ether the AcceptTcpClient or AcceptSocket methods. What get's
    returned from those methods is a new socket or tcpclient object that
    then will act as your communications channel.

    You may want to have a look here for some information on sockets in
    ..NET:



    Anyway, there are some code examples, etc. That is of course, not a
    complete reference on network programming, but it maybe a useful
    starting point.

    --
    Tom Shelton
    MVP [Visual Basic]

    Comment

    • Paul A. Steckler

      #3
      Re: Multiple listeners on a TCP/IP port?

      "Tom Shelton" <tom@mtogden.co m> wrote in message
      news:OTQbMu%23s DHA.684@TK2MSFT NGP09.phx.gbl.. .[color=blue]
      > My personal preference is to use a Socket instance and the async methods
      > - but, your problem is caused by a misuse of the TCPListener class. You
      > only need one instace of the TCPListener class. You accept connections
      > using ether the AcceptTcpClient or AcceptSocket methods.[/color]

      Oops, right.

      I've got my code working fine now, thanks.

      -- Paul


      Comment

      Working...