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

Windows: Basic echo fails to connect on 5.0.4 #103

Closed
LunarWatcher opened this issue Aug 21, 2019 · 11 comments
Closed

Windows: Basic echo fails to connect on 5.0.4 #103

LunarWatcher opened this issue Aug 21, 2019 · 11 comments

Comments

@LunarWatcher
Copy link
Contributor

5.0.4 and Windows don't appear to get along. All my unit tests are failing on 5.0.4, and attempting to compile it locally (git clone https://github.com/lunarwatcher/conan-ixwebsocket && cd conan-ixwebsocket && conan create . IXWebSocket/LunarWatcher) successfully compiles it, but prints errors:

ERROR: Unable to connect to echo.websocket.org on port 80, error: Connect error: No error
ERROR: Unable to connect to echo.websocket.org on port 80, error: Connect error: No error
ERROR: Unable to connect to echo.websocket.org on port 80, error: Connect error: No error
ERROR: Unable to connect to echo.websocket.org on port 80, error: Connect error: No error
ERROR: Unable to connect to echo.websocket.org on port 80, error: Connect error: No error
ERROR: Unable to connect to echo.websocket.org on port 80, error: Connect error: No error
ERROR: Unable to connect to echo.websocket.org on port 80, error: Connect error: No error

These aren't visible in the CI builds (I have no idea why)

For reproducibility, the code:

#include <iostream>
#include <ixwebsocket/IXWebSocket.h>
#include <string>
#include <vector>
#include <chrono>
#include <thread>
#include <ixwebsocket/IXNetSystem.h>

class SocketWrapper {
private:
    ix::WebSocket webSocket;
    std::vector<std::string> receivedMessages;
public:
    SocketWrapper() {
        webSocket.setUrl(std::string("ws://echo.websocket.org"));
        webSocket.setOnMessageCallback(
            [this](const ix::WebSocketMessagePtr& message) {
                if (message->type == ix::WebSocketMessageType::Open) {
                    std::cout << "Connected\n";
                    //webSocket.send(std::string("Congrats, your local version of IXWebSocket works!"));
                } else if (message->type == ix::WebSocketMessageType::Close) {
                    std::cout << "Closing socket...\n";
                } else if (message->type == ix::WebSocketMessageType::Message) {
                    std::cout << "Message received from server: " << message->str << std::endl;
                    receivedMessages.push_back(message->str);
                } else if (message->type == ix::WebSocketMessageType::Error) {
                    std::cout << "ERROR: " << message->errorInfo.reason << std::endl;
                } 
            });
        webSocket.start();

    }

    bool hasReceived() { return receivedMessages.size() > 0; }
    void close() { this->webSocket.close(); }
    bool ready() { 
        return this->webSocket.getReadyState() == ix::ReadyState::Open; 
    }
    void send(std::string message) { this->webSocket.send(message); }
};

int main() {
    std::cout << "Starting socket..." << std::endl;
    ix::initNetSystem(); // required for Windows
    SocketWrapper socketWrapper;
    int counter = 0;
    while(true) {
        std::this_thread::sleep_for(std::chrono::milliseconds(2000));
        counter++;
        if (socketWrapper.hasReceived()) {
            break;
        } else if (counter >= 5) {
            socketWrapper.close();
            ix::uninitNetSystem(); 
            throw "No response for 10 seconds: assuming failure";
        }

        if (socketWrapper.ready()) {
            socketWrapper.send("Congrats, your local version of IXWebSocket works!");
        }
    }
    std::cout << "Message received! Closing socket." << std::endl;
    socketWrapper.close();
    std::cout << "Socket disconnected." << std::endl;

    ix::uninitNetSystem(); // required for Windows.
}

For context, all the builds on 5.0.4 pass on Linux and Mac. The code is also identical in the 5.0.0 build and 5.0.4 build. I'm pretty sure this is triggered by v5.0.4 (or one of the versions in between that didn't work on Windows), but it could of course be my fault, but when it works on the other two operating systems and I have ix::initNetSystem(), I can't find anything else that could trigger it

@bsergean
Copy link
Collaborator

bsergean commented Aug 21, 2019 via email

@bsergean
Copy link
Collaborator

bsergean commented Aug 21, 2019 via email

@LunarWatcher
Copy link
Contributor Author

Whoops, my bad. I forgot to mention git checkout release/5.0.4. I keep the master branch up to date on the code itself, but keep versions in separate branches. The relevant code is on master, but to build 5.0.4, see the release/5.0.4 branch

@bsergean
Copy link
Collaborator

I just made a v5.0.5 with the potential fix I was talking about. Can you give it a try ?

@bsergean
Copy link
Collaborator

See 193da82

@LunarWatcher
Copy link
Contributor Author

Great, thanks! I've pushed the v5.0.5 branch. I'll update this reply when I start getting a status on them. It might take a few minutes before the first builds start succeeding.

@LunarWatcher
Copy link
Contributor Author

This triggered a compile-time error when linking:

ixwebsocket.lib(IXSocket.obj) : error LNK2019: unresolved external symbol "int __cdecl poll(struct pollfd *,unsigned long,int)" (?poll@@YAHPEAUpollfd@@KH@Z) referenced in function "public: static enum ix::PollResultType __cdecl ix::Sock
et::poll(bool,int,int,class std::shared_ptr<class ix::SelectInterrupt>)" (?poll@Socket@ix@@SA?AW4PollResultType@2@_NHHV?$shared_ptr@VSelectInterrupt@ix@@@std@@@Z) [D:\programming\projects\cpp\conan-IXWebSocket\test_package\build\ecbfb49
a4e2ea8618319be5f9e02c8e0621391fb\tests.vcxproj]
    Hint on symbols that are defined and could potentially match:
      "public: static enum ix::PollResultType __cdecl ix::Socket::poll(bool,int,int,class std::shared_ptr<class ix::SelectInterrupt>)" (?poll@Socket@ix@@SA?AW4PollResultType@2@_NHHV?$shared_ptr@VSelectInterrupt@ix@@@std@@@Z)
      "public: enum ix::WebSocketTransport::PollResult __cdecl ix::WebSocketTransport::poll(void)" (?poll@WebSocketTransport@ix@@QEAA?AW4PollResult@12@XZ)
      "int __cdecl ix::poll(struct pollfd *,unsigned long,int)" (?poll@ix@@YAHPEAUpollfd@@KH@Z)

I also see why - the poll function isn't defined in the ix namespace, but the declaration in the cpp file is.

@bsergean
Copy link
Collaborator

bsergean commented Aug 22, 2019 via email

@bsergean
Copy link
Collaborator

It's a bit gross to redefine my global poll btw, in the future I might have a named wrapper for it. But right now I'm just interested in seeing if this fixes your problem.

@LunarWatcher
Copy link
Contributor Author

Yep, that did the trick. It builds locally, and the CI build is looking good so far (built x86 and some of the x86_64 configurations on one of the MSVC versions). It prints output from the tests when expected to as well. Thanks!

These are also being pushed to conan as the soon as the CI builds finish.

@bsergean
Copy link
Collaborator

Excellent. Thanks for reporting the problem !!

bsergean pushed a commit to bsergean/vcpkg that referenced this issue Aug 22, 2019
Some test started to fail on Windows in the 5.0 branch.
```
ERROR: Unable to connect to echo.websocket.org on port 80, error: Connect error: No error
ERROR: Unable to connect to echo.websocket.org on port 80, error: Connect error: No error
ERROR: Unable to connect to echo.websocket.org on port 80, error: Connect error: No error
ERROR: Unable to connect to echo.websocket.org on port 80, error: Connect error: No error
ERROR: Unable to connect to echo.websocket.org on port 80, error: Connect error: No error
ERROR: Unable to connect to echo.websocket.org on port 80, error: Connect error: No error
ERROR: Unable to connect to echo.websocket.org on port 80, error: Connect error: No error
```
We figured it out and fixed it. This issue has more details. machinezone/IXWebSocket#103
vicroms pushed a commit to microsoft/vcpkg that referenced this issue Sep 9, 2019
* [ixwebsocket] update to 5.0.6 to fix Windows problem

Some test started to fail on Windows in the 5.0 branch.
```
ERROR: Unable to connect to echo.websocket.org on port 80, error: Connect error: No error
ERROR: Unable to connect to echo.websocket.org on port 80, error: Connect error: No error
ERROR: Unable to connect to echo.websocket.org on port 80, error: Connect error: No error
ERROR: Unable to connect to echo.websocket.org on port 80, error: Connect error: No error
ERROR: Unable to connect to echo.websocket.org on port 80, error: Connect error: No error
ERROR: Unable to connect to echo.websocket.org on port 80, error: Connect error: No error
ERROR: Unable to connect to echo.websocket.org on port 80, error: Connect error: No error
```
We figured it out and fixed it. This issue has more details. machinezone/IXWebSocket#103

* ixwebsocket: update to 6.1.0
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