I have a c# tcp server, I want to connect to the server via a html client page.
The problem: There is no simple way to create TCP sockets in Javascript on a browser side. Although solutions like Websockets allow to create something that resemble sockets, you can use them to connect only to servers that support Websockets. Not to any random servers that know nothing about HTTP.
so is there a solution to connect to my srver.
I have a c# tcp server, I want to connect to the server via a html client page.
The problem: There is no simple way to create TCP sockets in Javascript on a browser side. Although solutions like Websockets allow to create something that resemble sockets, you can use them to connect only to servers that support Websockets. Not to any random servers that know nothing about HTTP.
so is there a solution to connect to my srver.
Share Improve this question asked Oct 30, 2015 at 17:10 Med BesbesMed Besbes 2,0216 gold badges25 silver badges37 bronze badges3 Answers
Reset to default 4No. There just isn't. The browser is a tightly locked down environment. The only socket connection that you can open from JavaScript is WebSocket. Since it's your server, adding WebSocket support shouldn't be too plicated, and there are WebSocket libraries available for C#.
Maybe someone else will have an idea for you, but...
The best solution I can think of is for your server to support websockets.
The situation you described - along with connectivity issues for traffic passing through proxies and routers - is one of the reasons Websockets were introduced in the first place.
Bare in mind that Websockets can send and receive binary data. It's just that javascript make it more fortable to write text based messages.
Also, many NAT routers, Proxies and firewalls will block raw TCP/IP munication while allowing Http munication to pass through. This is why you have a better chance at connection establishment and retention when implementing the Websocket protocol.
I know I'm very late to this but, try creating a WebSocket "proxy".
Create a WebSocket server that connects to your raw socket server and passes on the data given to the WebSocket.
Hope this helps!