websockets / wscat

WebSocket cat
MIT License
2.25k stars 223 forks source link

Addexecute #58

Closed lotkao closed 6 years ago

lotkao commented 6 years ago

This addresses two issues:

lotkao commented 6 years ago

sorry for the opening and closing... :)

nwwells commented 6 years ago

I'm not experiencing the behavior you describe in https://github.com/websockets/wscat/pull/45#issuecomment-348815428 when I use master. That is to say, if I leave out --no-color, colors work properly, and if I add it, no colors are used. Moreover, --no-color seems more inline with other switches (currently just --no-check). Can you clarify your issue there?

Other than that, the execute option looks good.

nwwells commented 6 years ago

Oh, also, please clean up the whitespace to be consistent with the rest of the code. Spaces around else, if conditions, and what looks like bad indentation on L245.

lotkao commented 6 years ago

I will clean up the code.

lotkao commented 6 years ago

OK, I tested the master and it is working. Learned something new... I have reverted my changes regarding --no-color. I think the reason I had issues with it was because I started working on what came with the node install, and it does not have the --no-color yet... then when I forked and started working on the code here, I tried to merge my code and must have missed something that caused it to not work for me.

lpinca commented 6 years ago

https://github.com/websockets/wscat/pull/41 is probably a cleaner approach to the same problem.

lotkao commented 6 years ago

I tried to pipe, but in my case the connection was closed immediately, and I needed a way to send the command after the connection had been established.

Here an example using the current master:

$ echo '{"val1":1,"val2":2,"val3":3}' | wscat -c ws://[SERVER-IP]:[PORT]/url
{"val1":1,"val2":2,"val3":3}
error: Error: closed before the connection is established

Here an example using the wscat that includes the --keep-open https://raw.githubusercontent.com/websockets/wscat/13babed39ebbdbf813a0a922c4c219b744c62075/bin/wscat

$ echo '{"val1":1,"val2":2,"val3":3}' | wscat -c ws://[SERVER-IP]:[PORT]/url --keep-open
{"val1":1,"val2":2,"val3":3}
connected (press CTRL+C to quit)
> 

In both cases the query string was echo'd before the connection was properly established.

The --keep-open is not a solution for me. The way I am using wscat, I don't want it to keep the connection open indefinitely, that's why I even added the part where it calls ws.close() (with a wait time), after sending the passed on string.

Also, when using -x or --execute, I removed the < in-front of what the server returns, so I can parse the result without having to strip the character.

lpinca commented 6 years ago

We should probably rewrite the module, use streams and simplify everything. I like what @jnordberg did in wscat2.

I'll leave this to @nwwells.

nwwells commented 6 years ago

41 apparently doesn't work. Not sure how it could, tbh.

57 is similar, but without the raw output and --wait option.

I'm not wild about the interface, but we need to refactor loads of stuff anyway. For starters, using stdin should be the default. and you should close the connection on EOF, not on a timer. That being said, this PR doesn't prevent us from doing that in the future.