tcp streams problem c# - c#

When i try to connnect to a local IP everything goes wonderfully
but as soon as i use a normal ip, like to connect to a friend of mine outside the lan it just doesn't work

It's most likely a combination of firewall and port forwarding. In addition to opening up ports on your firewall, you'll need to forward these ports on your friend's router. PortForward.com is a decent resource if you're unfamiliar with port forwarding.

My first guess would be that you may be running into a firewall issue - is there a firewall operating between you and your friend? If so, do you have exceptions for it?
I suggest you use Wireshark to analyse what's happening at the network level.

Related

MSTSC.exe with STUN

Is it possible to connect mstsc.exe of one PC of one maching behing NAT to another machine behing NAT via STUN / hole punching.
If yes, could you please help how it can be done in c#.
As i understand there're lots of public stun servers over internet and the idea is to get some sorts of public address and then pass it as command line argument to mstsc ?
Thanks
Actually seems this problem - unability to access one PC behind NAT from other PC behind NAT is solved by Microsoft in 2009 (!).
It is possible to set a secure IPv6 name for a computer behind NAT and use it for remote desktop connection from outside PC because there's no need to come via nat for IPv6.
https://learn.microsoft.com/en-us/previous-versions//bb727045(v=technet.10)

What ip/port should i use for TCP Socket Server/Client connection?

i made basic TCP Socket server and client console application in c# with listener etc.. it works well with both server and client executed in same machine(127.0.0.1:10048). I want to try it with different machines in same network(both connected to same modem).
Which ip port should i use? I need help.
Thanks
You should use a port in the ephemeral port range. The ephemeral port range is the range of port numbers that is being selected from if you active connect to a server. The point is that it is free for use. Your kernel will skip the port numbers that are already in use so you don't have to worry about that either.
http://en.wikipedia.org/wiki/Ephemeral_port
And on top of this it is best not to hardcode your port numbers and ip adresses where you bind to connect or send to.
Make sure your OS firewall is turned off. For instance windows firewall can block this type of traffic.
Do not use just any free port that you detect is not in use. For instance you may not have an FTP or Telnet server running on your system, but that does not mean that you can just hijack those ports. From a functional point of view it will work if you do, but then you cannot run those services anymore somewhere in the future where you might need them, or your application will start failing. Which fails depends on which application is first started and starts using the port first.
When you bind an ip# you should use INADDR_ANY. Loopback communication will still work if you use this, you probably already did, most examples include it. Sending or connecting to an IP# should come from a configuration file (data driven) or commandline parameters. The IP# depends of course on the machine you want to communicate with.
Open your CMD and type ipconfig. There you can see your IPv4 address, that you should use to connect. The port doesn't really matter. Make sure to turn of your firewall(s) to allow a connection

Hosting a game on a PC - UDP or UPNP communication?

I've built a server-application for a game that I want general people to use. Now, since I've worked with client/server solutions before, I know how tedious it is to host connections on some computers.
So, I heard about these rumors that I would like to get confirmed.
Using UDP for "hosting" a connection is good, because it is rarely blocked by router-firewalls compared to TCP.
Using UPNP for communicating with a router is good, because it allows you to add port forwarding for the game, making your server reachable no matter if you're using TCP or UDP.
I don't care about the software-firewall people may use. What I care about is the router firewall functionality.
Any help would be appreciated.
Thanks!
For your two rumors,
I don't know, I have not worked with firewalls enough, but I would not call that one true. Most routers block everything (TCP and UDP) unless you explicitly ask it to forward it for inbound connections via hand setup or UPNP. If you don't tell the router what computer wants info coming in to port 12345 how will it know what to do when a user sends a unsolicited packet to it (the definition of being a server).
Yes, learning how to do UPNP will make it a lot easier for your users to host games, however you should still provide instructions for people who do not have UPNP turned on or their router does not support it.
The other thing you may want to look in to is learning how to add your program to the windows firewall client allowed list as that is what most of your users will have. See this SO question for more details.

Enable port forwarding with c#

I use a basic application that enables me to send a file over a tcp connection over the internet to a different computer. The way I managed to do that was to configure the router at my house and office to port forward all incoming traffic from port X to the corresponding computer. I am in a new office now and things work different in here.
There is a main router where all the offices may connect to. I connect my router to that router in order to have my own private network. I still want to be able to use my small application that I created in order to sync the files from my home computer and office computer. The only problem is that I dont have access to the main router therefore I may not open any ports in order to make my program work. I am new to networking so it will be nice if someone can point me to the right direction of how can I solve this. I think I have to let the router know to send all the traffic from port x to my computer. Moreover there are several routers so I dont know if it is possible. I think it should be possible because I am able to connect to my office computer via log me in for example.
It sill be nice if I can still use TCP protocols instead of a p2p since I already have all the functionality.
It would be much easier to connect from your office to your home computer. In this scenario, you have to setup port forwarding on your personal router (which you have already done!). If you connect from your home to the office, you will need to configure every intermediate office router (which your boss probably won't like).
In order to connect to your home network, I would look into setting up DDNS through someone like DynDNS. This will allow you to connect to me.example.com from wherever and have it resolve to your home address even when it changes IP addresses.
I found a nice page that talks about this in here. I will work on it... I am not sure if it works with the tcp protocol.

Testing a Remote Client-Server Application

Yesterday, I posted a question on some tips doing this Remote Client-Server Application in C#. So now, our group was able to create one. The problem is, we cannot think of ways on how we can test it since we are currently on different locations for our weekend break.
If anyone of you has any idea on how we can test it, please give us some hints.
Since you have both client and server programs, you can simply run them both on same PC and test them just like they would be on different machines. (use "localhost" or "127.0.0.1" as IP address of server)
It's enough to test program algorithm, and once it work on same PC, it should actually work on any two machines over internet/LAN.
Of course you should understand how networking actually works. Whoever you are connecting, must be visible to you. If you are going to connect via internet, server's IP address might not be enough. Something like http://www.showmyipaddress.com/ might show ISP's front, "white" address. And user, who run the server might have "grey" IP address, behind a NAT. So if you are going to use something like showmyipaddress.com , check your real IP address by typing "ipconfig -all" in windows command line. If ipconfig shows same IP, there are high chances it will work over internet (just check your firewall).
Have one of you setup the server, the other the client. Make sure your configurations match (use the server IP address, as you will probably not have a server name that can resolve via DNS).
Browse to http://www.showmyipaddress.com
Your ip address is listed there
Tell your ipaddress to the others (You need to open a port in your FW/router if you have one)
Tell them to change localhost to your ipaddress in the application and then connect.
you can use VMWare and run virtual machine (it's your choice), and run the server and the client in the same machine.
or you can run it on the same machine, just run : "ipconfig" on the command prompt ! get the IP and use it, or in some languages you can use the keyword "localhost", good luck

Categories