Cannot connect through tcp remotely - c#

I’m developing an app that connects on port 9050 through the public ip of my server. It works fine on lan but if I’m connected on a different network it fails what can I do to fix this?

first try from Command Prompt this command: telnet ip 9050
if it working means the port 9050 between your pc and the server already opened , otherwise you should check why and where the port is blocked (may be firewall in this case you need to create rule in firewall to pass ).

I don't have any code to go by and I know nothing about your network configuration, but I'll tell you what I generally do when debugging a network-enabled app. First, look at your firewall rules. This will obviously vary depending on what OS you're using but on Windows 10 application-specific permissions are located in Control Panel > System and Security > Windows Defender Firewall > Advanced Settings.
After making sure your app can get through your devices' firewall, check the router settings next. Your packets may not getting by whatever inbuilt security protocols are in place. Since your program works with LAN but not over the Internet, this is a distinct possibility. Also, depending on your network configuration, port forwarding may be necessary; if you're sending data via a public IP address, the router needs some way to know which device on the local network needs to be receiving it. Additionally, if you're trying to connect to your server from the same network you're hosting it on, make sure you use the IP loopback address, which I believe is always 127.0.0.1, or in C# IPAddress.Loopback. Public addresses often won't work when connecting to a local host.
If you're still having problems, I recommend using Wireshark. It's an advanced diagnostics tool that tells you exactly what is being sent and received over your network, and can help pinpoint otherwise hard to spot issues.

Related

How to open Ports through C#?

I'm kind of a beginner at programming, so I don't know what I'm about to ask is even possible. I want to make a TCP/IP connection to a server over WAN.
Both Client and Server programs were made by me they work just fine in a LAN. I'm now trying over a WAN. I know the server IP Address and the Port he's listening from, but as a client I can't make the connection. I supposed it's because the Port is not actually open/available.
How can I make this to happen in the server side? Is there a way for me to start the server (maybe as administrator) and for it to open the Port by itself? Is this a router or Firewall issue?
If I wasn't clear enough, feel free to ask.
Cheers.
PS: Let me put it this way:
If I make the connection in a LAN, it works. I set it to the local IP Address (192.168....) and choose whatever port I want and it works just fine. Once I put my public IP provided my ISP, it doesn't. I set the firewall router to accept everything and put a new rule in windows firewall to open port 100. What changed?
Please check the following list,
Server Firewall rules to exclude the desired port
Router Firewall to exclude the desired port
Check any installed security software blocking your desired port
Last and crucial! Open router interface and configure your NAT settings so the packets running via the desired port are served to your local server IP
If everyhting is fine and your ISP is not blocking the desired port then you will have no problem.
You can also visit canyouseeme.org in order to check that server listening alright!
Kind Regards,
KB

How can make my c# messenger works on the internet not only on the local networks?

I'm working on a simple c# messenger and its works on the local network only. Does somebody know what should i do to make it works on the internet?
The solution contains the server project that listening on a certain port, and a client project connect to the server with that port.
Your clients need to be able to communicate with the server, which means that either:
You need to host the server application on a computer that is directly connected to the internet.
You need to setup port forwarding on the router that controls internet access for your network.
In either case the clients will need to know the IP address to connect to, and any firewall interactions need to be considered. This may also include ISP firewalls, as some ISPs limit inbound connections to subscriber connections.
I won't go into the specifics of setting up port forwarding on a router... there are plenty of examples, and every router is different. Google will help you with this if necessary.
Ideally you should have a static IP address for this, or some method for the clients to locate the IP address that your server is hosted on. If you must run from a dynamic IP address (such as some ISPs still use for subscribers) then one of the Dynamic DNS options might work for you.
In-order to make it work on Internet a simple answer is you need to enable ports which is used for communication.Generally the ports will be blocked by the Companies firewall for security reasons.So contact your IT dept to enable the port.
Or Use common port like 80.

Remote access to SQL Server 2008 R2 [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
Reminder: Not on local area network. Is there a need some configuration of SQL Server? What connection strings will be used? C#.net is the programming language.
I don't know much about c# or ms sql server 2008 however I have set up many servers
every computer connected to the internet has an address... I'm sure you know that
now, if you use a router you will know that the router is connected to the modem, and is distributed through the router either through a wireless connection or ethernet connection (the cord), the way the router organizes things, is each computer is assigned a private ip address (something like 192.168.1.2)... this private ip address cannot be accessed by the outside world at all... BECAUSE the router gets a packet, and doesn't know where to put it, so it immediatlely drops it (forgets it)
this is really safe, because this means the only way a bad person could reach your computer is if they were on the same network... however, sometimes you need to host a server that NEEDS to be accessed by the outside world...
this is explained in a bit, just read on
now also every internet packet (which is anything sent around a network) goes to a specific port
these are referenced with regular numbers: ie (port 80, 160, 55, et cetera)
the great thing about ports is that different computer programs can handle different ports, at the same time!!!
so a computer can be running multiple servers at the same time. because the corresponding packet is sent to the corresponding port and therefore a packets meant for a specific application won't interfere by another accidentally.
so in conclusion what we need to do is tell our router to say...
is the port equal to the port used in the ms sql server?
if so take the packet and send it to (the private ip address of your server)
this is called Port Forwarding
you'll need to first find the private ip address of your server.
on windows you would need to go in the command prompt and type:
ipconfig
in Linux and Mac OS X
ifconfig
once you find the private ip address of the server. make it a static... meaning it cannot change
you'll have to research this as I do not use Windows
remember: Static IP Address
now once you get a static ip address for your server you'll need the port(s) that ms sql server 2008 uses.
once you find that you need to set up port forwarding on your router
this varies from router to router, however, if you have a Netgear router you can go to the web admin page by pointing your browser to http://192.168.1.1/
this will bring you to the netgear router admin page. find port forwarding/port triggering on the sidebar and click add custom service, then add the input.
Now the last step is to find your public ip address, to tell your friend, this is the address he/she will access the server with
you can find this real easily by going to http://www.ipchicken.com/
this should work
HOWEVER
if you only have a modem and get your internet directly through that. you have a different situation
all the packets get sent to the one computer connected to WAN port (meaning everything gets sent to your computer regardless of port)...
if this is the case
you should forget about port forwarding and just give your friend your public ip found using ipchicken or another method....
this should work, unless ms sql has an extra security layer that I don't no about
hope this helped
EXTRA
Windows by default adds a firewall that blocks all connections, except for the exceptions that are established after a bit of use... so first you will need to punch a hole in Windows firewall by adding an exception... this is done by clicking on the current connection you are using and clicking on properties or something, don't know exactly but once you find out how to do that. it's just a matter of telling the firewall that port "whatever port ms sql uses" is safe.
After that is done, your friend should be able to connect by entering your ip address as the host.... I don't know much about C# as I said, but what your friend would do is use the nessecary procedures as he or she would have if they were connecting to any old sql server. except the "host" is the ip address of your server.
I don't quite know what you mean by connection string, could you try to give me more info on that please?
All SQL servers can connect over tcp/ip and MS is no exception. If your machine is behind a NAT router or a firewall you need only setup the appropriate port access. On most consumer grade equipment this is known as a pinhole. You must allow inbound to the SQL Server port of 1433 or whichever one you choose.
Most ISP's these days give you one WAN ( real world ) IP address and that is the wan side of your router. All machines on the LAN side are normally on a 192.168.x.x / 10.x.x.x / 172.16.x.x address scheme which are not routeable as all routers are programmed to ignore those address blocks and not to pass them on.
Please keep in mind unless you asked specifically for a static IP address your WAN side will most assuredly change from time to time and so you will need to let your friend know what it has changed to via something like ipchicken.com
Additionally since LOTS of attackers look on the standard ports for MS-SQL I highly suggest you use some random port above say 10,000 instead of the standard 1433 if your device does not have the ability to limit the source address.

how can i send data over internet to any specific computer in subnet

I want to know how I can send or recieve data over internet to/from a computer in subnet
(this is specially in context to PPP users bcoz getting static IP is not so much in practice).
I actually want to create an application which can transfer file between 2 specific computer in WAN.
so what are things I need to know about to do the same..(ex. PRESENT IP or MAC ADDRESS etc..)
PROGRAMATICAL EXPLANATION ALTHOUGH PREFFERED,BUT IS NOT NECCESARY...
FTP?
There is a vast torrent of useful results in google, I seriously suggest to google before you ask here.
For instance, have a look at the top result: http://www.devarticles.com/c/a/C-Sharp/Network-Programming-in-C-sharp/
Apart from that, FTP, as suggested by Colin, may be what you're looking for. If you're new to using FTP in C# have a look at http://www.google.com/search?q=c%23+ftp
Put the information on a public IP server, so both computers keep polling if there is new data and send / download that data as needed. A single text file can hold necessary flags such as paths and other info you need.
server just need to be a web server, which means IIS or similar should be installed.
I'm thinking part of your question has to do with one of the computers not having a static IP address. If the two computers, A & B, don't know each others IP address, then an alternative is to use a server. Either A can store the information on the server to be picked up by B, or A can register his current IP address on the server for B to lookup and then connect to A, assuming firewalls don't interfere. Another scheme is that A and B can simultaneously connect to the server, and the server can relay data between the two.
Of course, all of this communication would be done using techniques such as those suggested by mafutrct and Colin.
This question sounds to me like the difficulties of NAT Traversal and trying to establish peer-to-peer connectivity over the Internet. I stumbled on this question researching the best way to set up Internet connectivity to a device that is sitting behind a firewall. I am assuming that the device behind the firewall has to initiate the connection, that a Internet server application (on a Public IP address) to at least manage the initiation of the connection is required, and the Internet server application may also have to act as a relay if the difficulties of NAT is not able to be traversed.
http://en.wikipedia.org/wiki/NAT_traversal
http://en.wikipedia.org/wiki/Peer-to-peer
A good example of this is LogMeIn. Where the application is installed on the computer that needs to be accessible over the Internet, that application communicates with the LogMeIn Internet servers, you can establish a connection to that computer either by initiating through the LogMeIn servers and connecting peer-to-peer over port 80/443 using NAT Traversal (this would be establishing a peer-to-peer connection) or by initiating through the LogMeIn server and the LogMeIn server acting as a relay if peer-to-peer is unable to be established.
Please note; you must have an application (something running) on both ends of the connection on the Internet, there is no other way. Just like FTP that was mentioned earlier (FTP Client, FTP Server)... but in this case it is peer-to-peer (basically you are writing your own Client and Server... or if you have to use a relay... Client--Relay--Server
http://en.wikipedia.org/wiki/LogMeIn
"The service connects the remote desktop and the local computer using SSL over TCP or UDP and utilizing NAT traversal techniques to achieve peer-to-peer connectivity when available."
The part I don't know is can the relay go in both directions; and I am figuring the device behind the firewall must have to constantly manage the open connection to the Internet Server that is the relay. Those are the questions I am wrestling with now.
Also, you may want to check out this post.
C# byte streams through TCP
From that time, till this date I have encounter so many problems with these four kinds of NAT that basically without an external server you cant do anything.
This is because, one computer can never find where the other one is located as suggested in the pic.
Here PC 'A' will never come to know about the port that corresponds to PC 'B' on R2B without an external server.Even more, if somehow u come to know about the ports you are still in a situation that the router wont allow you to access it if the request hasn't been made for your IP.

Identify user and machine on the local network

In my company we use small application called IPMsg, a messenger kind of tool to pass messages and file to other fellows in company, even it allows to multicast the message.
And also it lists the user name, host name and IP addresses of users.
How can it do that? There is no server present for message routing and when checked through netstat command in CMD it does not show any details like what protocol and port it is using to communicate.
There is source code also available on the same site which is in VC++. I didn't understand a line of code... (I'm a C# guy)
Can anyone explain me how it can do that?
One simple way would be to let the application listen on a certain network port, and when you start your instance of it, it tries to connect to that port on each computer on the same network. If that other computer has that port open, and answers correctly, then you have found another instance of the application.
IPMsg probably multicasts a request for all clients to report their user and host details.
A similar mechanism is used when Windows Explorer attempts to find other machines on a network. A good description of this type of multicasting discovery is described here.
IPMsg is a daemon which listens to incoming connections on a specific port which is the connection port. You can find out which port it used by using Wireshark.
Start wireshark, start listening on the interface where you have connected to LAN and then start sending any message, wireshark will show you the message on the screen with the port number also.
The application is a peer-to-peer software and doesn't require a central server software to route messages. it only has a small daemon which accepts incoming connections. This is the way Jabber Instant messaging protocol also works.
As you said it lists username, hostname and ip address of users, do you mean it pings the network and finds it? If yes, then it is actually possible to find the IP addresses of computers on the Local Network which requires you to know the subnet on which you are connected.
You can use ARP/ICMP Ping to know the hosts present on your network provided you enter the correct subnet information
Multicasting a message is also nothing special. It is a feature provided with all Networking Stacks.
If you want mutlicasting in .NET, it is allowed. Check this page on Code Project which gives a nice example

Categories

Resources