-2

So I made a chat program with connections codes like these

Client

Client code

Server

Server code

Now it works perfectly fine with LAN

Lan connection works

But for the love of god I can't figure out why WAN is not working

WAN is not working

Now I know that everyone at this point is blaming the firewall or port forwarding but ! I've done all that correctly and here's the proof ! When I use a port check tool to check if the server is up the server crashes cause I didn't place a try catch block to handle unknown requests yet !

enter image description here

And if your thinking maybe it's the DNS no it is not I entered the host address there and it still connects to the server ! Plus I checked with the autos the address it's trying to connect is indeed my IP ! How weird is that !!! I have been looking at my code for hours now... please help

Shaamil Ahmed
  • 378
  • 2
  • 7

1 Answers1

2

You don't accept any connection other than from 192.168.1.100. Create your TCPListener with IPAddress.Any not with serverAddress.

EZI
  • 15,209
  • 2
  • 27
  • 33
  • I just changed the code to IPAddress.Any, it had no effect on the connection. – Shaamil Ahmed Aug 10 '17 at 19:05
  • On top of which now even the open port check tool is unable to connect to the server ! 192.168.1.100 is a static IP of my machine on my network ! – Shaamil Ahmed Aug 10 '17 at 19:07
  • @ShaamilAhmed see an example https://stackoverflow.com/questions/21510204/c-sharp-tcpclient-send-serialized-objects-using-separators – EZI Aug 10 '17 at 19:11
  • IPAddress.Any would be useful if I was hosting my server on LAN but I am hosting my server on WAN meaning I have to listen to any incoming connections to my machines IPAddress I've done this before and I know for a fact that it should be 192.168.1.100 and not IPAddress.Any plus I tested ir with IPAddress.Any but it did not work ! On top even the Open port checker couldn't connect any longer !!! – Shaamil Ahmed Aug 10 '17 at 19:47
  • @ShaamilAhmed `IPAddress.Any would be useful if I was hosting my server on LAN but....` Seem you don't understand the concept. http://forums.devshed.com/programming-42/tcpclient-connects-localhost-192-168-1-localhostip-454849.html – EZI Aug 10 '17 at 19:57
  • @ShaamilAhmed : The IP that you give to the `TcpListener` is the IP that it will accept connections from. Specifying `192.168.1.100` will make it allow connections from _**THAT LAN IP ONLY**_ (WAN won't work), meaning only one computer (located in LAN) will ever be able to connect to it. `IPAddress.Any` is what you must use because it allows connections from _**any**_ IP address (LAN or otherwise). – Visual Vincent Aug 12 '17 at 07:51
  • But I tried that, if anything it made things worse ! – Shaamil Ahmed Aug 12 '17 at 17:50
  • @ShaamilAhmed : Then you have another problem. Perhaps the computer's firewall? Or the use of a proxy? -- I can assure you though that what I said is the case: You need `IPAddress.Any` (equivalent to `0.0.0.0`) to allow connections from _**any**_ IP, whether it is internal or external. – Visual Vincent Aug 14 '17 at 13:59
  • 1
    @ShaamilAhmed : It could also be related to a badly configured network (not implying yours is, but it's worth looking over the router settings). – Visual Vincent Aug 14 '17 at 14:06