简体   繁体   中英

How to connect HTML WebSocket to C++ Socket

I have an app where I am trying to connect to a C++ server which opens up a socket.

// Client side

var ws = new WebSocket('ws://<<IP:PORT>>');

In the server side, it is opening up a socket using

int sockfd = socket(domain, type, protocol) 

(ref: https://www.geeksforgeeks.org/socket-programming-cc/ )

Not aware of the c++ server implementation.

I was told that the server would start a WebSocket server to which my HTML app can connect.

But, the connection is not happening. I feel that the WebSocket on the client side is not same as socket on the server side and hence the connection is not establishing.

Please, someone, suggest what is wrong and how to make it right.

PS Please don't mind if it is a dumb question.

Since the server guys are not ready to change their implementation of the plain socket, as a workaround I created a C++ client which connects to the server using the plain socket. Then I am creating a WebSocket Server using NodeJs which executes the C++ client as a child process to get the data. So, my WebSocket client is now able to get the data from the main server through the NodeJs WebSocket interface server.

Cons:

  1. A dependency of the C++ client.
  2. Latency ( since network speed is not a factor now, it works ).

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