Skip to content

Simple connection attempt from browser does not work #22

Description

@marcusegues

I am having an issue setting up a simple connection from a browser to the node example given.

Server code:

var http = require("http");
var StompServer = require('stomp-broker-js');

var server = http.createServer();
var stompServer = new StompServer({server: server});

server.listen(9999);

stompServer.on('connecting', function() {
    console.log("CONNECTING")
})

stompServer.subscribe("/**", function(msg, headers) {
    var topic = headers.destination;
    console.log(topic, "->", msg);
});

stompServer.send('/test', {}, 'testMsg');

Browser code:

  import * as Stomp from '@stomp/stompjs';

  // connect to local server
  const ws = new WebSocket('ws://localhost:9999');

  const client = Stomp.over(ws);

  client.debug = () => undefined;

  client.connect(
    {},
    frame => {
      console.log('Connected', frame);
    },
    (error: any) => console.log('Error', error)
  );

I am just copying what is in the docs as regards the server code. I am using @stomp/stompjs client to connect.

The error I get is: WebSocket connection to 'ws://localhost:9999/' failed: Error during WebSocket handshake: Unexpected response code: 400

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions