html javascript connect to raw socket

前端 未结 2 1559
-上瘾入骨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.

提交回复
热议问题