Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Alkor San
    @alkorsan
    yes
    Vitaly Shukela
    @vi
    Advanced mode will be binary by default, but warn about it unless explicitly given --binary (-b). The warning would state that it is different from simple mode.
    Alkor San
    @alkorsan
    ah yes
    Alkor San
    @alkorsan
    just to inform you, removing the --line and - work fine for that command that caused race conditi
    for ((i=0; i<20; ++i)) { printf '%s\n' '{ "id":2, "method":"Page.navigate", "params":{"url": "http://www.google.com"} }' | "$websocat" --no-close  --one-message  $WSurl; } | nl
         1  {"id":2,"result":{"frameId":"A0D16F665F658EC82EB2E38019B6E06A","loaderId":"E6CA0A5B70A22A020C2FC6DC863AB742"}}
         2  {"id":2,"result":{"frameId":"A0D16F665F658EC82EB2E38019B6E06A","loaderId":"3CB4643FF7C24D9BF8899507A4E37DE5"}}
         3  {"id":2,"result":{"frameId":"A0D16F665F658EC82EB2E38019B6E06A","loaderId":"47486E2C88388760F22DCA81E7E7EB14"}}
         4  {"id":2,"result":{"frameId":"A0D16F665F658EC82EB2E38019B6E06A","loaderId":"D0D7CFBEF1A144E5A14AFF52FF37FAE9"}}
         5  {"id":2,"result":{"frameId":"A0D16F665F658EC82EB2E38019B6E06A","loaderId":"C09E5AD02096ED87A3DADB06054C4EB6"}}
         6  {"id":2,"result":{"frameId":"A0D16F665F658EC82EB2E38019B6E06A","loaderId":"294738F5E854AA4789DCBCC761DB1A84"}}
         7  {"id":2,"result":{"frameId":"A0D16F665F658EC82EB2E38019B6E06A","loaderId":"3BB9735D663E758F198EBBB190624029"}}
         8  {"id":2,"result":{"frameId":"A0D16F665F658EC82EB2E38019B6E06A","loaderId":"D67991A3273ECE632A6F12901B5BEA5A"}}
         9  {"id":2,"result":{"frameId":"A0D16F665F658EC82EB2E38019B6E06A","loaderId":"AF0E60399DDA8C98B0D375CE8D5F78DC"}}
        10  {"id":2,"result":{"frameId":"A0D16F665F658EC82EB2E38019B6E06A","loaderId":"F5D139A7B3903621F32BCEDF787C63D2"}}
        11  {"id":2,"result":{"frameId":"A0D16F665F658EC82EB2E38019B6E06A","loaderId":"A26D49CC8FAB4B691496279BE332A0F1"}}
        12  {"id":2,"result":{"frameId":"A0D16F665F658EC82EB2E38019B6E06A","loaderId":"645712F9F74782FF6BF3DDDBAEFACE7B"}}
        13  {"id":2,"result":{"frameId":"A0D16F665F658EC82EB2E38019B6E06A","loaderId":"CA215E0BCFA2D3999547E4A280FCD051"}}
        14  {"id":2,"result":{"frameId":"A0D16F665F658EC82EB2E38019B6E06A","loaderId":"9F84E4F0425E3DD3EB1EF41900ECCBB3"}}
        15  {"id":2,"result":{"frameId":"A0D16F665F658EC82EB2E38019B6E06A","loaderId":"97C2EAC6D10E51DECD4B1FA592AD3B56"}}
        16  {"id":2,"result":{"frameId":"A0D16F665F658EC82EB2E38019B6E06A","loaderId":"8047E8EC081F22E65195D3E8393477BD"}}
        17  {"id":2,"result":{"frameId":"A0D16F665F658EC82EB2E38019B6E06A","loaderId":"F450A5D1A550F5C6A0CB2EF025812FA2"}}
        18  {"id":2,"result":{"frameId":"A0D16F665F658EC82EB2E38019B6E06A","loaderId":"27517AB9C4AF3CACFFC357ED1A13AB72"}}
        19  {"id":2,"result":{"frameId":"A0D16F665F658EC82EB2E38019B6E06A","loaderId":"2449CC688BE3C883C9C0049B54F33C5A"}}
        20  {"id":2,"result":{"frameId":"A0D16F665F658EC82EB2E38019B6E06A","loaderId":"CE2F1C085C2C4330E93B8501B8C124C6"}}
    Vitaly Shukela
    @vi
    It should be OK for small chunks ot text that are printed in one move. But if the text is large or is printed step by step, then it can be a problem. Prepare some example of misbehaviour?
    Alkor San
    @alkorsan
    but using printf '%s' instead of printf '%s\n' is still confusing , it doesnt tell you nothing, it stay opened and don t gave even an error
    Vitaly Shukela
    @vi
    There is warning visible with RUST_LOG=warn. I plan making such warnings visible by default and being silienced by -q option (not implemented yet).
    Also maybe I make it auto-insert \n for the last line if it is trimmed.
    Alkor San
    @alkorsan
    RUST_LOG=warn is same doesnt show any worning
    Also maybe I make it auto-insert \n for the last line if it is trimmed. :+1: :sparkles:
    Vitaly Shukela
    @vi
    $ printf 'qwe' | RUST_LOG=warn websocat -l - ws://echo.websocket.org; echo
     WARN 2018-06-23T23:37:31Z: websocat::line_peer: Throwing away 3 bytes of incomplete line
    Alkor San
    @alkorsan
    ah noww it works, it have to be run in the same subshell like this
    Vitaly Shukela
    @vi
    Throwing away incomplete lines would become an option. It is needed when there is a stream of messages (one message per line) that can end abruptly (e.g. due to some program crashing). You don't typically want to send a half of a message.
    Alkor San
    @alkorsan
    for ((i=0; i<20; ++i)) { printf '%s' '{ "id":2, "method":"Page.navigate", "params":{"url": "http://www.google.com"} }' |  RUST_LOG=warn "$websocat" --no-close  --one-message  $WSurl; } | nl
     WARN 2018-06-23T23:38:57Z: websocat::line_peer: Throwing away 79 bytes of incomplete line
    ok

    It should be OK for small chunks ot text that are printed in one move. But if the text is large or is printed step by step, then it can be a problem. Prepare some example of misbehaviour?

    yes please seems dangerous

    Vitaly Shukela
    @vi
    Or maybe make an option to not throw away such lines and auto-activate it only with --one-message.
    Alkor San
    @alkorsan
    how can websocat know if my line is not complete? i understand that \n make websocat think that the line is not complete , is there other case that can happen apart from this?
    Vitaly Shukela
    @vi
    { printf '{'; printf '"id":2,'; sleep 1; printf '"method":"Page.navigate",'; printf '"params":{"url": "http://www.example.com"}'; printf '}'; } |  websocat -1nt --origin http://127.0.0.1:9222 --protocol tcp - "$WSurl"; echo
    Works for me if I remove sleep 1, but fails with {"error":{"code":-32700,"message":"Message must be a valid JSON"}} if retain sleep.

    Similar example that should be reliable:

    { printf '{'; printf '"id":2,'; sleep 1; printf '"method":"Page.navigate",'; printf '"params":{"url": "http://www.example.com"}'; printf '}\n'; } |  websocat -l1nt --origin http://127.0.0.1:9222 --protocol tcp - "$WSurl"
    {"id":2,"result":{"frameId":"661F2E6D3FBA99B88B296DC874CB47A0","loaderId":"2A3EAFEC6C8FEA9BED9336E636EFE099"}}

    (note the added -l option)

    Alkor San
    @alkorsan
    a websocket message can contain multiple lines, does this -l, --line Make each WebSocket message correspond to one line does it mean that each websocket message is converted to one line, or does it mean every line is considered one message please?
    Vitaly Shukela
    @vi
    For JSON-encoded messages it should not be a problem. It is easy to find 1 JSON to 1 line.
    For other uses there is a planned option -0 (--null-terminated) to make zero byte end the line instead of LF.
    Alkor San
    @alkorsan
    -0 :+1:
    Vitaly Shukela
    @vi
    For completely arbitrary messages you need packet-oriented protocol like UDP or unix-seqpacket (obviously without the line mode)
    Note that there is maximum size of the message. Overriding it is also a planned option.
    Alkor San
    @alkorsan
    what is the max size now?
    Vitaly Shukela
    @vi
    65536 bytes.
    Alkor San
    @alkorsan
    thanks
    i m still chocked with the sleep 1 that broke the exemple, why -l was the solution to this? sleep doesn t do anything there i beleive
    Vitaly Shukela
    @vi
    Do you know the difference between TCP and UDP?
    Alkor San
    @alkorsan
    yes
    stateless stateful?
    Vitaly Shukela
    @vi
    Stream-oriented vs message-oriented.
    Shell's pipeline | is like TCP.
    You feed bytes to it on one side, and get bytes from other side. One write(2) operation can result in multiple read(2)s (and vice versa).
    Vitaly Shukela
    @vi
    Imagine people arriving by bus, staying in line (queue) and getting to a stadium. A portion of people leaves the bus and joins the line. Another portion (from other side of the queue) is allowed to proceed by security guards.
    A "chunk" of people from one bus won't necessarily lead to the same "chunk" allowed in.
    Arraiving buses: [abcdef] [ghijklmn] [opqrst]
    Line: abcdefghijklmnop
    Allowed in: [abcd][efgh][ijkl][mnop][qrst]
    Websocat's --one-message (without --line) mode is just to get one chunk and call it a day message.
    Websocat's --one-message --line is to get chunk after chunk until we see the LF character.
    Without --line boundaries between messages are defined by underlying operating system behaviour which is typically not guranteed (like boundaries between content in packets in TCP).
    And sleep 1 ensures that partial data actually gets seen by websocat (not joined together by operating system before getting to websocat).
    Alkor San
    @alkorsan
    fantastic thank you
    Vitaly Shukela
    @vi
    Automatic --line insertion in advanced mode needs to be implemented carefully. It should discriminate stream-oriended addresses like exec: or tcp: or - and packet-oriended like udp: or seqpacket: and insert the overlays only to the former.
    (There may be special UNIX-specific addresses like exec-seqpacket: in future).
    Alkor San
    @alkorsan
    can I say that --line will force websocat to wait until it receives EOF?
    Vitaly Shukela
    @vi
    Currently it always waits for the \n byte.
    After receiving it all preceeding bytes (maybe including the \n itself if --linemode-retain-newlines) are called a message and proceed to the other "address".
    Also the reverse: each message is converted to a line (\n is forced at the end, internal \ns are replaced by spaces).
    Alkor San
    @alkorsan
    how can the message contain \n and in the same time websocat wait for \n to close?!!
    Vitaly Shukela
    @vi
    I mean the reverse direction (e.g. from websocket to console).
    "wait for \n and closing" happens in to-websocket direction, "replace with spaces and append \n" happens in from-websocket direction.