简体   繁体   中英

Can C# connect to a WebSocket using Socket(Not WebSocket) class

I have a c# app that communicates over socket. I want to code a web app that can connect to c# app over socket. As you know c# has different classes for Websocket and Socket .

Questions :

1-) If I use WebSocket for JavaScript , can it connect to existing Socket structure on c# or is it required to re-code it to WebSocket ?

2-) is there any other performance efficent way to do ?

A WebSocket connection uses a socket, but with a predefined way of framing the data, while if you use a socket directly, you can define your own way of framing the data, however the other end must know how the data is framed in order to understand it.

Answering your question: In Javascript you can only connect to sockets that are running as WebSocket, since the WebSocket Javascript client will try to communicate in the "WebSocket" way and won't understand anything different.

However, if you really need Javascript to access a regular socket, you can try to use an intermediary proxy like WebSockify , but you cannot connect directly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM