Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser failing on valid stream urls. #75

Open
davidawad opened this issue Apr 4, 2018 · 2 comments
Open

parser failing on valid stream urls. #75

davidawad opened this issue Apr 4, 2018 · 2 comments

Comments

@davidawad
Copy link

I'm trying to subscribe to the following stream url.

$ wsta wss://stream.binance.com:9443/ws/bnbbtc@depth
Connected to wss://stream.binance.com:9443/ws/bnbbtc@depth
{"e":"depthUpdate","E":1522849782404,"s":"BNBBTC","U":56348828,"u":56348828,"b":[["0.00177540","205.23000000",[]]],"a":[]}
{"e":"depthUpdate","E":1522849783404,"s":"BNBBTC","U":56348829,"u":56348829,"b":[["0.00176290","0.00000000",[]]],"a":[]}
# . . . 

I keep hitting this line when trying to run the following code to read a stream from binance.

I think the regex being used there needs to be changed.

here's the cpp i'm running.

#include "easywsclient.hpp"
#include "easywsclient.cpp"

#ifdef _WIN32
#pragma comment( lib, "ws2_32" )
#include <WinSock2.h>
#endif


#include <assert.h>
#include <stdio.h>
#include <string>
#include <memory>

int main()
{
    using easywsclient::WebSocket;

// #ifdef _WIN32
    // INT rc;
    // WSADATA wsaData;

    // rc = WSAStartup(MAKEWORD(2, 2), &wsaData);
    // if (rc) {
        // printf("WSAStartup Failed.\n");
        // return 1;
    // }
// #endif

    std::unique_ptr<WebSocket> ws(WebSocket::from_url("wss://stream.binance.com:9443/ws/bnbbtc@depth"));
    assert(ws);
    // ws->send("goodbye");
    // ws->send("hello");
    //
    while (ws->getReadyState() != WebSocket::CLOSED) {
        WebSocket::pointer wsp = &*ws; // <-- because a unique_ptr cannot be copied into a lambda
        ws->poll();
        ws->dispatch([wsp](const std::string & message) {
            printf(">>> %s\n", message.c_str());
            if (message == "world") { wsp->close(); }
        });
    }

// #ifdef _WIN32
    // WSACleanup();
// #endif

    // N.B. - unique_ptr will free the WebSocket instance upon return:
    return 0;
}

here's my error:

$ g++ -I. -Wall -stdlib=libc++ -std=c++1z read_stream.cpp -o client

$ ./client                            09:50:21
ERROR: Could not parse WebSocket url: wss://stream.binance.com:9443/ws/bnbbtc@depth
Assertion failed: (ws), function main, file read_stream.cpp, line 36.
fish: './client' terminated by signal SIGABRT (Abort)
@davidawad davidawad changed the title wss url failing on valid stream urls. parser failing on valid stream urls. Apr 4, 2018
@dhbaird
Copy link
Owner

dhbaird commented Apr 4, 2018

Hey David, this is a known issue- easywsclient does not support SSL connections. There are some forks however, that have added SSL and you may want to use what they did.

@davidawad
Copy link
Author

hey @dhbaird can you link me to one?
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants