I am trying to write a basic app that will read data off a port. Here is my code:
static void Main(string[] args)
{
int port = 5600;
string server = "MyDevLaptopName";
TcpClient tcpClient = new TcpClient();
tcpClient.Connect(server, port);
NetworkStream stream = tcpClient.GetStream();
byte[] data = new byte[256];
stream.Read(data, 0, data.Length);
Console.ReadLine();
}
When I run the app above I get this error on the tcpClient.Connect command:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 10.90.91.19:5600
I am not sure why my computer will not respond (I am totally new to TCP ports and such).
Is there a different way I need set this up to read data from a TCP port?
Things I have checked:
- Windows Firewall is completely off.
- The IP address listed in the error is the internal IP address of my development machine (the machine I am trying to connect to).
- I do have Symantec Endpoint Protection, but it is controlled by Group Policy and it would be difficult for me to get turned off (but I can do it if need be).
Update:
There is a main frame server that is supposed to be sending TCP data to that port. I do not control that machine/server or the method that it sends the data. I am just trying to read the data that is sent to the port.
Update II:
The main frame is actually sending the data to a VM at my company. I then use the technique found here to redirect that TCP traffic to the same port on my machine (where I hoped I could just read it off).
Update III:
The mainframe is the client and I need to be the server!. Once I realized that I got things working.
I would try with another port number, are you in control of the server as well? if so try to follow these steps:
C# Tutorial – Simple Threaded TCP Server
as you will see there you can listen in this way:
and you can connect in this way:
it seems trivial and it is, but port number is not a detail as some ports are not available or blocked by firewalls or so…