Re: System.Net.Sockets.Tcplistener

Discussion in 'ASP .Net' started by Gaurav Khanna [.NET MVP], Jul 25, 2003.

  1. Hi!

    If the port is already being "listened" upon by another application, then
    you will need to sniff on the incoming packets to determine the data you
    wish to work upon. However, if you have to write the application to "listen"
    on a specified port, wait for an incoming stream of data and then work upon
    the data, then System.Net.Socket.TcpListener is what you are looking for.
    Here's a sample pseudo code that will listen on port 2323:

    TcpListener tcpListen = new TcpListener(2323);
    tcpListen.Start();

    while(1)
    {
    while(tcpListen.Pending()==true)
    {
    // accept an incoming request...
    TcpClient tcpClient = tcpListen.AcceptTcpClient();

    // ask another thread to work on the client so that this thread can
    listen for more incoming requests...
    }

    // make the current thread sleep here so that the CPU can relax
    }

    Regards,
    Gaurav Khanna
    --
    ----------------------------------------------------------------------------
    ----------
    Microsoft MVP - .NET, MCSE Windows 2000/NT4, MCP+I
    WinToolZone - Spelunking Microsoft Technologies
    http://www.wintoolzone.com/
    OpSupport - Spelunking Rotor
    http://opsupport.sscli.net/
    ----------------------------------------------------------------------------
    ----------

    "MB" <> wrote in message
    news:...
    > I am new to sockets programming, but I need something that seems to be

    very
    > simple.
    >
    > I need to monitor a port on a server running a background application in
    > order to integrate to another application. I know the port number and the
    > vendor will provide me the binary sequence of the data stream going to

    that
    > port. This is all they will provide.
    >
    > On this stream (among other info) I will receive an active or inactive

    bit
    > that represents the state of the application icon on the system tray. When
    > active it turns green, when inactive it turns red.
    >
    > Is it possible to snoop this port using the namespace
    > System.Net.Sockets.Tcplistener or another namespace ?
    >
    > Is it possible to read the data stream without affecting the backgound
    > application, which is also reading the stream.
    >
    > Thanks a lot
    >
    > Marco
    >
    >
    >
    >
    Gaurav Khanna [.NET MVP], Jul 25, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jeff
    Replies:
    0
    Views:
    1,496
  2. Rick
    Replies:
    0
    Views:
    1,123
  3. VincentWong
    Replies:
    1
    Views:
    549
    VincentWong
    Dec 29, 2003
  4. Torsten Brasch
    Replies:
    5
    Views:
    6,197
    Feroze [MSFT]
    Jan 7, 2004
  5. PJ6
    Replies:
    5
    Views:
    13,871
Loading...

Share This Page