I am new to websockets, please excuse me if the answer to my question is too obvious.
I'm using websocket-sharp, as my goal is to build a Unity3D client that connects to a server. (Actually I want to build it for webGL platform, so the client will be written in javascript). For now, both client and server are written in C#.
When compiled on localhost it works perfectly, also with multiple clients and also over a secure connection using a self-signed certificate. It also works fine if the client connects to an echo server (ws://echo.websocket.org).
So I moved forward and I tried to connect two of my computers. The idea was to run the server on linux and execute the client on a mac, so I substituted "localhost" for the linux IP on both client and server codes. When I execute it, Unity (client) keeps saying me "Not a local IP address" and it doesn't connect.
I thought this could be a firewall issue, and that first I should open the port used... Is that the case? If so, how can I open a concrete port on mac and on linux?
Check the bindings.
WebSocketServer(System.Net.IPAddress.Any, port);
Test if you can make a connection to ip:port.
iptables -L for listing the configured rules in Linux.
Finally I solved it. It was an issue with the server code, I don't know where was the error. Instead of using my c# server I used Node.js, and it works fine. I can connect from other computers without problems.
Related
I'm developing an UWP app which needs to be the server for a win32 client application, which is not to be changed if possible. Now the problem is I can connect to my uwp server application if I connect to the hostname or IP address of my computer. In contrast if I use localhost or 127.0.0.1 I can't get a connection.
I'm running this command constantly to enable the connection without running it, it doesn't work at all. "CheckNetIsolation.exe LoopbackExempt -is -n=Packagename"
I also executed some tests, and found out that on the computer under company IT, it only works when using the IP address. Therefore with the identical setup on a computer which is not under the companies IT, it works as expected.
So I expect there's a problem with the way my machine is configured.
We have an proxy for all outgoing connections. Another thing when I use a win32 server and client I have no problem to connect to localhost, so it seems that my machines dns configuration is in general right.
Do you have any ideas how to torubleshoot this, or what I can try to find out where my connection attempt is going. Maybe the UWP application is trying to connect over the proxy?
Having some trouble with websocket-connection within the local network.
Scenario:
For my laptop (Win7) I've written a service which opens a websocket-server to port 2014. Because websockets aren't enabled by default for windows 7 I'm using the supersocket library ( http://www.supersocket.net/ ).
For the Client I've written a android app with sencha touch and Phonegap. To enable websocket- support for android devices with version lower 4.4 I've integrated the phonegap websocket- pugin.
The reason is to open a websocket-connection between the android device and the laptop to control the laptop by the android app. Both devices are members of the same local network.
The problem:
After installing both applications (windows service and android app) I've tried to connect my android device with the service from the laptop. First step is to open the connection on the client:
var connection = new WebSocket('ws://192.168.178.21:2014');
But in the event-logs of my windows service there is no successful connection logged.
After that I opened the browser of my laptop and tested the same code - successful. Client and Server could communicate with each other.
So I've tested the websocket-support on my android device: changed the websocket-url to
var connection = new WebSocket('ws://echo.websocket.org');
and could connect to the server -> Android websockets are okay.
Third step was to disable my firewall and check the connection with Wireshark:
Screenshot:http://www.directupload.net/file/d/3710/y9t79npy_png.htm
192.168.178.21 -> Laptop IP
192.168.178.23 -> Android device IP
So it seems that the packets reach my laptop but not the service. Additional tried to use the secure wss:// protocol - no victory.
Don't have any ideas anymore. Would be a pleasure to get some help :)
So it seems that the packets reach my laptop but not the service.
Could it be that the server is binding to a specific IP address or hostname? Often servers will implicitly bind to all interfaces, such as 0.0.0.0, but sometimes they bind to one specific interface. If that happens, then you need to connect to that same interface.
You said your client is connecting to ws://192.168.178.21:2014, but could it be that the server is binding to 127.0.0.1 or localhost or your hostname, and therefore doesn't see the request? That could explain why the laptop received the request, but not your service.
Then again, you said you tried it from your local browser, and it worked. Did you use the same IP address, or did you use 127.0.0.1 or localhost? Assuming you used the same IP address, 192.168.178.21, then that would indicate it's not the bind issue I described.
Sorry, that's all I can think of at the moment.
After some time i´ve found the solution:
Had to add the firewall rule to the public firewall options.
Thanks for your help:)
I'm currently using Alchemy Websockets as my WebSocket solution, however this is proving to be a pain as I've spent quite a number of hours trying to figure out why I can't get it up and going on my WebRole (both on Compute Emulator and cloudapp.net itself). It runs okay locally.
I'm aware of this question that was asked previously, and I've followed everything in the code and done everything suggested, so I can't get why I still can't connect to my WebSocket server. I've tried connecting using WebSocket.org's Echo Test as well as an Android client (leveraging on Autobahn). I'm quite sure it's not a client-side issue anymore considering that both ways don't work, but more of a server-side issue (what is stopping me from opening the WebSocket server on Azure?!).
In summary, what I've done so far:
Included TCP InputEndpoint 8080 in my Azure
Start the WebSocket server in either Global.asax or RoleEntryPoint with port 8080
Tried connecting using both Echo Test & Autobahn for Android
If it helps, I've previously tried SuperWebSocket Server. I understand that the creator Kerry Jiang has uploaded some Azure samples, but the Command Assembly baffles me and I don't want that kind of extra logic in my application (I just want something that I can plug and play), so I decided to ditch that altogether.
Both Alchemy Websockets and SuperWebSocket Server work perfectly fine locally, but when it's on Azure (either emulator on uploaded on cloudapp.net) I can't seem to connect at all. Any guidance please...?
When using WebSocket with cloud-hosted VMs, a number of things can go wrong:
The cloud service might have firewalls in place that block any (non-standard) ports by default. On Amazon EC2, you can configure open (unblocked) inbound ports via AWS management console and the respective configuration of the "security group" that applies to the EC2 instance your WS server is running on.
Even if you use a standard Web port (like 80) and this port is open in the firewall, there might be a proxy, load-balancer or other so-called intemediary in place that is not WebSocket aware.
When running over non-local networks, there are all kinds of intermediaries that might interfere. For example, mobile networkwork providers have intermediaries that are too stupid for WebSocket (which uses the HTTP standard Upgrade mechanism .. it is standard .. but there is a lot of broken stuff out there).
To work around for 2. and 3. (and also in general), you probably want to run WebSocket over TLS (secure WebSocket .. WSS) in production. Running over TLS, and terminating the TLS connection at your server, no intermediary can interfere (there are exceptions even here .. so called MITM HTTPS proxies that unwrap the TLS .. but that only on some corporate networks and relies on the proxy being able to dynamically installing certificates in the user's browser).
To make a robust WSS connection, you MUST make sure the server certificate used is accepted by browsers without any problems. If it is self-signed e.g., a browser would normally not accept, but ask the user if he nevertheless wants to accept. With WS, the browser will not render such dialogs, because WS is a so called "subresource". Hence: make sure your cert is 100% ok.
With 5. being done, WebSocket (WSS then), will work (almost) all the time. Mobile, enterprise, public internet.
I am working on a project where I am making my own SMTP server. This is pretty much working but there is a bit of a problem.
When I run my SMTP server on my development machine and have a php script to send the email or telnet from my local computer to the local smtp server it works fine and my program receives the SMTP messages and I send the relevant responses.
I am then copying the program on to a server and running my smtp server and when I telnet from the server to the local smtp server i.e. telnet localhost 25 it works.
If I then try and connect to my smtp server through a remote PC on the same network and attempt to telnet to it I get Connecting to 192.168.1.74 (this is the address of the server)...could not open connection to the host, on port 25: connect failed and if I run the php script http://192.168.1.74/send-mail.php it fails.
On the smtp server code when I bind the socket I have tried binding to 127.0.0.1 and 192.168.1.74 on port 25 but it makes no difference.
Why would this not be working from a remote PC making the connection to the server but locally it works fine.
Thanks for any help you can provide.
A couple stabs in the dark here, but:
Does the server have a firewall running? If so, have you made the appropriate exceptions for port 25?
Is the remote PC really on the same network (i.e. same subnet)? If you've got a router in between you'll have to forward the port appropriately.
Found out what the problem was, I was being dumb, when I set the network card to be static I forgot to add the default gateway. Now that I have done that it is working now as expected.
Thanks everyone for your help and suggestions.
How do I redirect an incomming request on port xxx to localhost:yyy on windows 7?
Development Server (vs 2008) only allow access from localhost which isnt good enough. I need to test my app from various computers.
Thanks for the suggestions guys, although I found the answer myself.
I downloaded Microsoft SOAP Toolkit version 3 and started MSSoapT, created a formatted trace listening on port 8080, forwarding to host: 127.0.0.1 port: 3804. My problem was I used "localhost" and not "127.0.0.1".
Now every request made to my development machine from other computers through port 8080 will be redirected to port 3804 where ASP.NET Development Server is statically set to listen when debugging VS.NET webapps.
On the command prompt.
$> netsh
$> interface portproxy
$> add v4tov4 listenport=xxx connectaddress=127.0.0.1 connectport=yyy protocol=tcp
See: http://technet.microsoft.com/en-us/library/cc776297%28WS.10%29.aspx#BKMK_1
If this really is for some testing, you could create a server which listens on a port, and when it receives an incoming connection spawns a thread that opens a connection to the actual local server, and afterward just waits for data to come in either end and shuffle it along to the other end. If either socket closes, the worker thread would terminate. This is obviously not a scalable solution, but for testing it should easily do the trick.
Not really sure what you are looking for. However port forwarding will be relevant when you have a router in place and you need to explicitly forward a request on a specific router port to a specific IP and port on a LAN computer. If you want to access the web server from other LAN computers on the same network then http://ip-address should just work fine. Also make sure that your web server is listening on the LAN IP and is not just bound to localhost.
I'm using windows 7 64 bit and couldn't get the Microsoft SOAP Toolkit to work on my machine for port forwarding and didn't like the free port forwarding software I found out there so I just changed my VS 2010 web app to use local iis, I know this doesn't help people running 2008 but it works if you have 2010... Here's a screen shot of my change: I'm doing this for testing on the iPad...