jmesnil / stomp-websocket

Stomp client for Web browsers and node.js apps
http://jmesnil.net/stomp-websocket/doc/
Apache License 2.0
1.43k stars 586 forks source link

Example NOT Works #125

Open lreisoliveira opened 8 years ago

lreisoliveira commented 8 years ago

This.. not work

script src="http://cdn.sockjs.org/sockjs-0.3.min.js

// use SockJS implementation instead of the browser's native implementation
var ws = new SockJS('ws://localhost:3000/websocket');
var client = Stomp.over(ws);

console.log(ws); console.log(client);

Response:

Uncaught ReferenceError: Stomp is not defined(anonymous function) @ (index):34 sockjs-0.3.min.js:27 XMLHttpRequest cannot load ws://localhost:3000/websocket/info. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

I haven't this: /info its only ws://localhost:3000/websocket

why?

isaacgainey-wsc commented 7 years ago

The url you're giving sockjs is incorrect. /info is a json obj, not a ws end point. And because not a websocket you can manual search for it on your browser. /info's job is to direct how SockJS actually connects to the server (whether it's though websocket, short polling, long polling or others) then sockjs does all that fun business in the back-ground while you treat it purely like a websocket.

tip: Also don't give sockJs the full url like that unless you're telling it to connect to completely different url than your base page. Just give it the basic endpoint, you'll know you've found it because when you access it through the browser you see Welcome to SockJS!. Use that endpoint for SockJs to connect to.