TcpListener won't accept connections,
Members - Reputation: 448
Posted 06 November 2012 - 10:40 PM
I copied the library onto both my desktop and laptop and built a very simple console program on both ends for testing. When I set up my desktop as the server and my laptop as the client, the program ran perfectly. I will say this though. When I ran the program for the first time, Windows notified me about VSHOST.EXE and asked me if I wanted to allow it, which I did. Now, when I switched it, running the exact same programs but on opposite computers, my desktop (the client) couldn't form a connection, eventually giving me an 'Error 10060'. Curiously enough, when I ran the server program on my laptop for the first time, Windows didn't ask if I wanted to allow VSHOST.EXE.
Is Windows security preventing incoming connections? And, if it is, how can I ensure that any of my distributed applications won't suffer from this same problem? I plan on having each client also be a listener to listen for random updates (unless there is a better way to do this).
A little more info: The important Listener code
private TcpListener Listener;
Listener = new TcpLIstener(IPAddress.Any, 4040);
TcpClient Client = Listener.AcceptTcpClient(); <-Pretty sure the listener isn't making it past this point
Important Client code
public string IP; //pass an IP Address or hostname to this
TcpClient Client = new TcpClient();
IPostEntry Host = Dns.GetHostEntry(IP);
var Address = (from h in Host.AddressList
where h.AddressFamily == AddressFamily.InterNetwork
NetworkStream ClientStream = Client.GetStream();
byte InfoBuffer = Encoding.ASCII.GetBytes(Info);
ClientStream.Write(InfoBuffer, 0, InfoBuffer.Length);
Members - Reputation: 782
Posted 07 November 2012 - 06:30 AM
Your sending/receiving code also looks fine
It looks like a firewall is just blocking the connection, just look at firewall settings, i don't think you really can make sure your program will work though a firewall, especially if its listening for a connection, after all that's what they are designed for right?
Edited by Xanather, 07 November 2012 - 06:31 AM.