Azure VPS as TCP server - c#

I'm using an Azure VPS to host a TCP server (raw sockets) but the external client is timing out when it tries to connect to the server. I've already opened the TCP ports on Azure Portal.
It works locally so it can't be a problem on the code.
(Note that the address shown in the server print is just the local address, the client is pointing to the server external address)
Server running:
Client timeout:

Well it turns out the problem was the VM firewall. Just added the inbound rule and it worked!

Related

.NET Service System.Net.Sockets.SocketException: 'No such host is known'

I deployed a .NET Windows Service on Azure Virtual Machine running Windows Server with an opened port that allow me to connect to it, this service is like a server using socket. The problem is that when I try to connect from my PC to that hosted server it doesn't work and I get this exception: System.Net.Sockets.SocketException: 'No such host is known'. The port is opened and visible from my PC. Can someone tell me why I get that exception? If I run locally all works ok.
The Exception seems to be a DNS issue. I am not familiar with C#, from networking, you could check the followings on your side:
Windows service is running and the port is listening on the Azure VM.
The port is allowed for outbound traffic from your PC and Inbound traffic on your Azure VM. Check the VM firewall settings on both sides between your PC and Azure VM. Also, you could check the NSG settings follow this. You could use telnet vmpublicIP port on your PC CMD to verify network connectivity.
Verify your PC can resolve the address of hosted server if you connect it via its DNS name. You could use the NSlookup or DIG to verify this. If it's DNS issue, you also could add a line in hosts file (located in %WINDIR%\system32\drivers\etc on windows) mapping the hosted server's IP to a name.
Hope this helps.

Client server (service) application connecting locally but not over the network

I have created a windows service server program in c# which will receive data messages from a serial port and then send those messages to any clients that have connected to the server. I have also developed the client program (windows form) in c#.
Originally the server program was developed as a console application to make development easier. While running the server as a console application the connections to the clients worked well, I could run a client on the same PC as the server and also connect a client on a laptop connected to the same network.
The connection method is:
-client starts up
-client broadcasts (udp) to a specific port
-server responds to the UDP broadcast
-client initiates a TCP connection with the server using the IP address obtained from the UDP response
Since changing the server from a console application to a windows service I can no longer connect the client program running on the laptop to the server using this method. The client program running on the same machine as the server connects successfully. Can anyone offer some advice on what to investigate?
To solve the issue I was having I added a new rule in the firewall settings of the machine running the server service application. I allowed the port used on incoming connections and this solved the problem for me.
I also changed the network discovery procedure:
Server broadcasts every second to a port (UDP)
Client awaits the broadcast packet from the server
Client establishes a TCP connection with the server using the IP address obtained from the broadcast packet

"Server cannot accept argument" exception thrown by FTP server in IIS in Azure VM

Following the code i'am using to connect to the FTP server.
client.Mode = FtpMode.Active;
client.ActiveModePorts = new Range(10000, 10001);
client.Connect(ftpModel.ftpServer, ftpModel.ftpPort);
client.Login(ftpModel.ftpUser, ftpModel.ftpPassword);
I'am using Ftp.dll nuget packaage for development.
The error Thrown by Visual Studio
FTP Firewall support
Firewall Inbound Rules
Inbound rules of Azure VM
Inbound rule in my local Machine
In Azure VM, we can't use FTP in active mode, please try to use passive mode.
In active mode FTP the client connects from a random unprivileged port (N > 1023) to the FTP server's command port, port 21. Then, the client starts listening to port N+1 and sends the FTP command PORT N+1 to the FTP server. The server will then connect back to the client's specified data port from its local data port, which is port 20.
Here is the connection appears as follows:

Client can connect to Server on same machine using localhost, but not when IP Address or hostname is used

I'm using VS Express 2012, setting up a simple server and client on a Windows Server 2008R2 machine with all of the latest updates installed. When I have the client try to connect to the running server using "localhost" as the host to connect to, everything works fine. When I have the client try to connect to the running server using the IP address or the actual host name, I see the "No connection could be made because the target machine actively refused it 192.168.5.159:13000 ..." error message. netstat shows my server is listening on the same port as reported in the error message (13000). I've modified the Windows Firewall setting to allow my client and server to communicate through the Windows Firewall. I've added an entry to my Hosts file associating my host name with the IP address. Any suggestions as to what else I can try? All of this is being done on a private (work) network.
Usually when you set up a server, you need to specify the hostname or IP the server listens on. When you initialize a server to use localhost, you can only use localhost to connect to it.
If you want a server to accept requests from every source you need to see if you can use a wildcard to accept all connections. For example 0.0.0.0 is used a lot.

c# socket server - deploying, starting, stopping

I'm a little confused when it comes to socket servers in terms of deploying it online.
Running locally is fine as most tutorials get you to make a server application and a client application which I can execute. Done all that for awhile now and I'm happy with it but now I want to try it using a web host.
How would I deploy the socket server to my web host and then run the server? do I just upload the program to the server and run www.mywebpage.com/mysocketserver (assuming the program is called mysocketserver.exe)
may sound like a stupid question but I'm having one of those brain dead moments.
[Edit]
Great answers guys thank you. Shame I can only mark one as the answer.
Most hosting services are website related: you upload your website to their server and the host takes care of provisioning the application.
However you haven't written a website that is served by a web server, but a socket server, which is more akin to the web server itself that runs a website.
As a result you will need a host that will allow you to install and run applications, such as a Virtual Private Server service, rent a physical server or use a cloud service such as Amazon EC2.
You usually Remote Desktop or SSH into the server you are renting (or own) to upload and start the application either as a normal application, a Service or a Daemon.
Once you have installed your socket server on the host server and started the application running you should be able to contact your service using the IP address for your server and the port that you are running your socket server on.
For example, if your ip address is 10.0.0.1 and you've written your socket server to listen on port 1234, you should be able to contact your service at address 10.0.0.1:1234.
Take into account firewalls allowing access to that port.
You will also then be able to use a DNS service such as DynDns to assign a domain name to that ip address.
You can't do that unless your socket server is using HTTP as a protocol.
You are using a port for your server, right? The ports are used to identify which application to talk with.
When you browse the web using "http://something" you really say let me get the stuff which can be found on the IP 1.2.3.4 (DNS lookup) using port 80 (which is registered for HTTP). You don't have to specify the port in the browser since all browsers know that HTTP uses port 80.
So what you are really should do is to put the socket server on your host and tell your customers/users that they can connect to your socket server at port XXX on host "www.mywebpage.com".
If you've built a client you'll just hard code the port in it or specify the default port automatically.
The problem in the Internet is the routing/name translation, so that mywebpage gets translated into the correct IP address.
Either your webserver needs a fixed public IP address or you need to use a service like dynds which will dynamically map your changing IP address to the static name.

Categories

Resources