General TCP Listener Question

haydena

New member
Joined
Feb 15, 2012
Messages
4
Programming Experience
1-3
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?
 
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.
 
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?
 
"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.
 
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.
 
Back
Top