observing / thor

The WebSocket god of thunder
MIT License
1.29k stars 154 forks source link

Better documentation for Generators #11

Closed CraigChilds94 closed 9 years ago

CraigChilds94 commented 9 years ago

I'm looking to use this as part of a project and I'm required to send specific messages, with which I react in different ways. This is the case for the majority of Web Applications and so would make sense to include more information here.

It would be nice if you gave more obvious examples or documentation as to how we can write our own generators to do what we wish.

3rd-Eden commented 9 years ago

@CraigChilds94 Sorry for lacking on documentation here. The best what you can do is look at the generator file that we're using by default: https://github.com/observing/thor/blob/master/generator.js#L3-L39

As you can see it exposes 2 methods, one for generating UTF-8 messages and one for binary. These are called with a size param and an callback. The size is the max byte length of the string (not the length of the string) and the callback assumes an error first pattern.

The --generator flag assumes an absolute path to the js file you want to use.

CraigChilds94 commented 9 years ago

@3rd-Eden Thanks for this. It was more in the way of where I need to pass the actual message through; but I've had a play around and can now see what is required. Thanks for such an awesome tool!

smtchahal commented 6 years ago

@CraigChilds94 @3rd-Eden I don't understand where the actual message is supposed to be passed either...

CraigChilds94 commented 6 years ago

@smtchahal I'd love to help you but I honestly can't remember as this was 3 years ago!

3rd-Eden commented 6 years ago

It been ages for me as well, so I had to dig in the codebase to figure out how it was done. So the CLI it self does not allow you to specify the message that is send to the server, it uses the supplied generator files to create the payload. The generator file specifys a function that receives 2 arguments:

  1. The size (--buffer) of the payload that needs to be generated
  2. The callback function where you pass the generated message in as second argument

So by default, we just generate some random strings and send that over the wire, if you actually want to send meaningful content over the wire you need to create your own message.