microsoft / cpprestsdk

The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
Other
8.01k stars 1.66k forks source link

VS2015 websocket can't connect !!!! #548

Open kyo055 opened 7 years ago

kyo055 commented 7 years ago

I use the websocket to connect the server with the code as :

   web::websockets::client::websocket_callback_client  client;
    try
    {
    client.connect(U("ws://39.108.171.172:8089")).wait();
    }
    catch (const std::exception&e)
    {
        std::cout << e.what() << std::endl;
    }

but always get the error with : set_fail_handler: 7: End of File

And when I try to use the Winsocket2, I can connect with the server.

princetomy92 commented 6 years ago

@kyo055 . You have saved my time.thanks .Now my sockets connected successfully

princetomy92 commented 6 years ago

MY SOURCE CODES

websocket_client client; //start socket connection to server try {

    std::cout << "started //";
    client.connect(U("wss://sadfshafdghs.com/ws?account_id=4de3f308f2f8d3247a70w2228f94e0d2aea&ws_key=reception")).wait();
    std::cout << "\n...........1st.........;";
}
catch (const std::exception&e)
{
    std::cout << e.what() << std::endl;
}

    //send messages to the server

    //websocket_outgoing_message msg;
    //msg.set_pong_message();
    //std::cout << "\n...........2nd.........;";

    //std::string data = "hii";
    //client.send(msg).then([]() { 
    //  
    //  
    //  
    //  
    //  /* Successfully sent the message. */ });
    //std::cout << " Successfully sent the message.";
    //std::cout << "\n...........3rd.........;";

    //receive messages from the server

    client.receive().then([](websocket_incoming_message msg) {
        std::cout << "receiving data from socket";

        return msg.extract_string();

    }).then([](std::string body) {

        std::cout << "displaying the data";

        std::cout << body << std::endl;
    });

    //close the connection
    //client.close().then([]() {

    //  std::cout << "successfully close socket connction";

    //  /* Successfully closed the connection. */
    //});
princetomy92 commented 6 years ago

i dont know how to parse data from body. i got the responses in body. MY JSON RESPONSES

data{"action":"refresh_dashboard","data":{"users_list":[{"user_id":"901e6076asff351cfc2195fb86f8438sa26","extensions":["1002"],"name":"sM"},{"user_id":"cc3f94ecc14ee9c55670dcde9adc1s887","extensions":["1006"],"name":"sS Kiran"},{"user_id":"6c29ebdb34asae1761fdf9423c573087979","extensions":["1003","+1732451as4180"],"name":"sNath"},{"user_id":"74d5bas5a9sasaca1faa4c2f217ce87b621d8","extensions":["1008"],"name":"sRaju"},{"user_id":"a7ad7e73bsasf93ea83c8efdc1723cba198","extensions":["1007"],"name":"sArif"},{"user_id":"b55146df5sas93ec8d09e5fe12a8a4c1108","extensions":["1001"],"name":"sdsds dsd"}]}}

TyrionQu commented 4 years ago

@kyo055 How did you resolve that problem: "set_fail_handler: 7: End of File"? I met the same question.