Howdy Monks! I am back again with another question. I am trying to establish a persistent connection to a gateway/websocket so i can add some functionality! I were trying to use REST::Client, but when the time come to do the connection/handshake with the actual gateway, i got something like "protocol not supported", which I took as REST::Client didnt support wss. I can connect to the api server all day long and read messages with REST::Client, but i cannot seems to post responses from my bot.

So this is where I started floundering around and copy/pasting code while not understanding it. Besides copy/pasting code, I believe IO::Socket would be a better approach to this, but I dont fully understand the whole server/client thing great either.

I would post some code but it would be the first failed attempt with the "protocol not supported" error.

To post code, I will post some psuedo code because I am not very sure as to what I need to do to actually make the request and read the responses with IO::Socket.

Do I need a server, or a client, or do I need a server and client? any help is very much appreciated :)

use strict; use warnings; use IO::Socket; use JSON; my $wss = 'ws://gateway'; my $client = IO::Socket->new($wss, 5000, tcp); #most examples use loca +lhost instead # do I do the handshake query here before the loop and then go to +the loop and start filtering # responses? while(1){ #filter responses }

I appreciate any hints of wisdom.


In reply to Persistent connection to a websocket/gateway (wss://) by james28909

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.