Results 1 to 6 of 6

Thread: General TCP Listener Question

  1. #1
    haydena is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Feb 2012
    Posts
    4
    Reputation
    0

    General TCP Listener Question

    I apologize in advance if I butcher this question or any portion of my description herein. I'm a noob and not sure exactly what I'm asking.

    I have an application that is basically a map that is fed a stream of x/y coordinates, which update as units move about in the field. When I fire up this application, I provide a user/pass and then a bunch of things fire up including the "Communication Agent." When I open the Communication Agent window, it basically is a form with a listbox that updates as a bunch of things happen. A couple of the things I notice happening are "Starting TCP/IP Communications," "Looking for server at 10.10.123.456 (which happens to be a server on the same subnet I am on)" and "Connection (7890) established." In poking around the .NET forums, as best I can tell I'm looking at a TCP Listener? I started wondering if I could "listen" without having to use the "Communication Agent" application provided by the vendor. I mucked around with this code sample TcpListener Class (System.Net.Sockets) with the only modifications being to the port number (changing it to 7890) and changing "IPAddress.Parse("127.0.0.1")" to "IPAddress.Any." When I run this Listener, nothing happens. When I run the Listener and then log in to my vendor provided application, the console window starts displaying the information that would otherwise be shown in the "Communication Agent" window. I'm trying to understand what is happening and determine if there's a way I can read this stream of information without having to run any of the vendor supplied software and stream the data in to my own application? Is the reason that no data is streaming to the console window, until I log in with the vendor provided application, because the listener sample doesn't provide a connection to the server.....and when I log in with the vendor provided application the connection is made....and the reason the sample Listener gets the the message is that it was bound to the port before the Communication Agent had a chance to and now that a connection to the server has been made, the sample listener gets the message?

    Am I on track at all? Is there a way to get the listener sample to stream the info without having to log in through the vendor supplied interface? Do I have to provide a connection to the server?

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is online now VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    12,743
    Reputation
    1618
    The TcpListener IS the server. It listens on a port for client connection requests. If you see nothing then presumably there is no client requesting a connection. The steps are basically this:

    1. The server creates a TcpListener and listens for requests on an IP address and port number.
    2. The client creates a TcpClient and connects to the server IP address and port number.
    3. The server receives the request and accepts the connection.
    4. The server creates a TcpClient for its end of the connection.
    5. The client and server each get a NetworkStream from their respective TcpClient and write and read data over that stream.

  3. #3
    haydena is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Feb 2012
    Posts
    4
    Reputation
    0
    Thank you. The overview is helpful.

    If I know data is coming in on port xxxx but can't connect to that port because "address already in use" is there any way to get at the same data? Would cloning the port accomplish this?

  4. #4
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,470
    Reputation
    2732
    "address already in use" means you are trying to bind a socket to an ip endpoint already in use. In most cases you do not need to bind TcpClient to a specific local ip endpoint. My guess is you misunderstood the documentation and tried to bind the client to the servers ip endpoint, rather than connecting to it.

  5. #5
    haydena is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Feb 2012
    Posts
    4
    Reputation
    0
    Playing with the MSDN TCP client connection example, I am able to send a message to the server but never get a response back. Is the server expecting a particular message?

  6. #6
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,470
    Reputation
    2732
    Is the server expecting a particular message?
    Once connected, if the server doesn't start sending data it must be expecting some kind of input first.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking