html javascript connect to raw socket

前端 未结 2 1556
-上瘾入骨i
-上瘾入骨i 2021-01-22 12:40

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

相关标签:
2条回答
  • 2021-01-22 12:57

    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 comfortable to write text based messages.

    Also, many NAT routers, Proxies and firewalls will block raw TCP/IP communication while allowing Http communication to pass through. This is why you have a better chance at connection establishment and retention when implementing the Websocket protocol.

    0 讨论(0)
  • 2021-01-22 13:00

    No. 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 complicated, and there are WebSocket libraries available for C#.

    0 讨论(0)
提交回复
热议问题