Can you get TCP Socket support in it? I have been scouring the web trying to find any evidence whatsoever that there is support for this feature in order to get a user-mode console application to host a socket TcpListener object on an Azure Virtual Machine, because it's not working for me. I know that Azure web sites have support for .NET WebSockets, but that's a different, HTML5 concept, than hosting a TCP socket from a console application in my Virtual Machine.
Asked
Active
Viewed 930 times
1
-
3Note, that WebSockets and TCP sockets are completely distinct concepts. – usr Jun 15 '14 at 11:13
-
@usr You're right. I got them confused. I will update my question! Thanks for pointing out that WebSockets are part of the HTML5 standard, whereas my concern is towards TCP sockets! – Alexandru Jun 15 '14 at 14:32
-
1Did you add the appropriate endpoints? – haim770 Jun 15 '14 at 15:14
-
@haim770 Yes, I *think* so, unless there's anything I'm missing, but...I added a new endpoint to create a TCP port mapping from a single port (6490) on the domain itself to the same port (6490) on the virtual machine, and that's the same port that the TcpListener is on! – Alexandru Jun 15 '14 at 15:27
-
1What about Windows Firewall? – haim770 Jun 15 '14 at 15:28
-
@haim770 I added two new rules, a new inbound rule and a new outbound rule on that same port to allow all access! – Alexandru Jun 15 '14 at 15:28
-
@haim770 Is there anything else you can think of? I read your profile, you do a lot of VM'ing on Azure...it might be a lot to ask, but what if you tried opening up a socket on one of your VM's that's running the server I marked up here (server and client are both C# Console Applications): http://stackoverflow.com/questions/24225531/tcpclient-not-connecting-to-remote-server – Alexandru Jun 15 '14 at 15:42
-
1@Alexandru, Unfortunately it's not *my* VMs, i'm just the developer and cannot run arbitrary code on it. Can you provide the host-name and port so i can try from here? – haim770 Jun 15 '14 at 15:48
-
@haim770 Sure. It's ovidius.cloudapp.net:6490 – Alexandru Jun 15 '14 at 15:49
-
1`new TcpListener(IPAddress.Parse("127.0.0.1")`. You're actually binding to `127.0.0.1` (localhost) only? – haim770 Jun 15 '14 at 15:50
-
1Did you try with `new TcpListener(IPAddress.Any)`? – haim770 Jun 15 '14 at 15:52
-
@haim770 On the server-side, I'm just binding to localhost, yes. I haven't tried IPAddress.Any, though...hmm, good point. You think maybe localhost doesn't resolve to the actual IP of the VM in question? – Alexandru Jun 15 '14 at 15:53
-
1If you're binding to `127.0.0.1`, only requests *to* `127.0.0.1` will be bound. When you access using `ovidius.cloudapp.net (191.238.37.130)`, your listener is refusing the connection. – haim770 Jun 15 '14 at 15:55
-
1Binding to `127.0.0.1` basically means that you can only access the service *from within the VM itself*. – haim770 Jun 15 '14 at 15:56
-
@haim770 I just tried updating it to use IPAddress.Any, but this also seems to have the same results, but I'll also work to try and use the VM's internal IP as a bound IP...on the off-chance that might be it. – Alexandru Jun 15 '14 at 15:57
-
@haim770 IPAddress.Any resolves to 0.0.0.0, so I think that might be a problem...but I will try explicitly the local IP of the VM. – Alexandru Jun 15 '14 at 16:00
-
1You can get the instance IP using `RoleEnvironment`. – haim770 Jun 15 '14 at 16:00
-
1Also, what type of endpoint have you created? `Input / Internal / InstanceInput`? – haim770 Jun 15 '14 at 16:06
-
@haim770 Just a TCP endpoint on that port from the Azure portal online. I wasn't given any of those options when creating the Azure Endpoint. Also, just looking at how to get the IP using RoleEnvironment right now! Hardcoding the host IP to the local or public IP of my VM did not work. – Alexandru Jun 15 '14 at 16:09
-
@haim770 Something like this? RoleEnvironment.CurrentRoleInstance.VirtualIPGroups.First().Value.VirtualIPEndpoints.First().Value.PublicIPAddress; – Alexandru Jun 15 '14 at 16:10
-
1That should work, but if `IPAddress.Any` didn't work, i doubt the explicit instance IP will... – haim770 Jun 15 '14 at 16:11
-
@haim770 Ah, I'm gonna try this instead: RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["WebSocketServer"].IPEndpoint.Address;...that's the name of the endpoint I'm using on that port. – Alexandru Jun 15 '14 at 16:15
-
@haim770 I'm actually having issues getting the Microsoft.WindowsAzure.ServiceRuntime to load up with my application. I tried copying it locally, and deploying with it in the directory but it crashes on startup due to this error (and the answers did not help): http://stackoverflow.com/questions/16560053/the-type-initializer-for-microsoft-windowsazure-serviceruntime-roleenvironment – Alexandru Jun 15 '14 at 16:21
-
@haim770 I tried to delete the old endpoint at port 6490 and also, in conjunction with hosting the TCP socket at the Internal IP of the server, it seems to have worked. I'm honestly not sure what was causing the issues, but you can read more about my trials and tribulations here: http://stackoverflow.com/questions/24225531/tcpclient-not-connecting-to-remote-server/24233931#24233931 – Alexandru Jun 15 '14 at 20:52
-
@haim770 Honestly, the only difference I can think of is I had firewall rules to allow that port on this time, before actually creating the endpoint...so weird. – Alexandru Jun 15 '14 at 20:52
-
1@Alexandru, weird indeed. Thanks for updating. – haim770 Jun 15 '14 at 20:53
-
@haim770 Yeah, its strange...so if you ever come across this issue, you know what to do :) the answer I gave in my other question somewhat related to this one is more complete in terms of the steps I took...and that worked. It may be that those steps cause a chain of events to take place on the Azure cloud network that end up with my original endpoint route working when I recreated it...I don't know. – Alexandru Jun 15 '14 at 21:05
1 Answers
1
Yes, confirmed by myself that they do. It looks like my issues were with a faulty Azure endpoint.
Update: Just thought about it some more...I think it comes down to the following two issues:
- You need to host the server on the Internal IP of your Azure Virtual Machine, not localhost or 127.0.0.1 like I was doing.
- You need to not have the "ENABLE DIRECT SERVER RETURN" feature enabled on your Azure endpoint.

Alexandru
- 12,264
- 17
- 113
- 208