thruway / raw-socket-transport

Raw Socket Transport for Thruway Client and Router
4 stars 1 forks source link

Handshake is required #1

Open danelowe opened 5 years ago

danelowe commented 5 years ago

Crossbar router would give me an error "invalid magic byte (octet 1) in opening handshake: was 0x{magic}, but expected 0x7f" when attempting to use RawSocketClientTransportProvider

WAMP protocol requires a handshake with 0x7f followed by an octet that specifies max message size and serialization format.

I got it to work by modifying startTransportProvider:

    public function startTransportProvider(ClientInterface $client, LoopInterface $loop)
    {
        $this->client = $client;
        $this->loop   = $loop;
        $connector    = $this->connector ?: new Connector($loop);
        $connector->connect($this->address . ':' . $this->port)->then(function (ConnectionInterface $connection) {
            $connection->write(pack('C4', 0x7f, 0xf1, 0x0, 0x0));
            $this->handleConnection($connection);
            $connection->on('data', [$this, 'handleData']);
            $connection->on('close', [$this, 'handleClose']);
        }, 'printf');
    }

Not sure I know enough at this time to do a PR

mbonneau commented 5 years ago

@danelowe Thanks for the code snippet - I believe the raw socket support may not be compatible because the raw socket was implemented while the spec was under heavy revision.

I will take another look at this and see if I can figure out a way to work with both the old raw socket implementation and the way the spec is now.

danelowe commented 5 years ago

I ended up modifying just the RawSocketTransport class to send the header, and also to receive the first 4 octets from the router as it’s response. I can send through some more snippets when I get a chance, but they’re pretty rough.

On Sat, 17 Aug 2019 at 6:25 AM, Matt Bonneau notifications@github.com wrote:

@danelowe https://github.com/danelowe Thanks for the code snippet - I believe the raw socket support may not be compatible because the raw socket was implemented while the spec was under heavy revision.

I will take another look at this and see if I can figure out a way to work with both the old raw socket implementation and the way the spec is now.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/thruway/raw-socket-transport/issues/1?email_source=notifications&email_token=AAHBZASRVFHHDFHZE52DOELQE3WJZA5CNFSM4IMC3FIKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4PLL2I#issuecomment-522106345, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHBZASDICAWCZF53XNR35DQE3WJZANCNFSM4IMC3FIA .