I'll try to shot as possible - do not waste your time.

I need each socket connection to have own id sent by javascript (client side) like ws://domain.com:port/USER_ID. Already two weeks on it. Pleae help me - bear guaranteed :)

My code as follow:

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-12 +52"> <title>New Page 1</title> </head> <body> <p>#!/usr/local/bin/perl -w<br> use IO::Socket::INET;<br> use Digest::SHA1 qw(sha1);<br> use MIME::Base64;<br> use Protocol::WebSocket::Frame;<br> # auto-flush on socket<br> $| = 1;<br> # creating a listening socket<br> my $socket = new IO::Socket::INET (<br> LocalHost =&gt; '0.0.0.0',<br> LocalPort =&gt; '8080',<br> Proto =&gt; 'tcp',<br> Listen =&gt; 5,<br> Reuse =&gt; 1<br> );<br> die &quot;cannot create socket $!\n&quot; unless $socket;<br> print &quot;server waiting for client connection on port 7777\n&quot;; +<br> while(1){<br> if($socket-&gt;connected) {<br> #$socket-&gt;connect($port, $ip) or die $!;<br> print &quot;connektintas \n&quot;;<br> }<br> # waiting for a new client connection<br> my $client_socket = $socket-&gt;accept();<br> my $digest;<br> # get information about a newly connected client<br> my $client_address = $client_socket-&gt;peerhost();<br> my $client_port = $client_socket-&gt;peerport();<br> print &quot;connection from $client_address:$client_port\n&quot;;<br> # read up to 1024 characters from the connected client<br> my $data = &quot;&quot;;<br> $client_socket-&gt;recv($data, 1024);<br> print &quot;received data: $data\n&quot;;<br> if($data=~/WebSocket-Key\:\s+(.*?)\s+/gs){<br> $digest = encode_base64(sha1($1.&quot;258EAFA5-E914-47DA-95CA-C5AB0DC8 +5B11&quot;));#magic stream<br> }<br> # write response data to the connected client<br> $client_socket-&gt;send(<br> &quot;HTTP/1.1 101 Switching Protocols\r\n&quot;.<br> &quot;Upgrade:websocket\r\n&quot;.<br> &quot;Connection:Upgrade\r\n&quot;.<br> &quot;Sec-WebSocket-Accept:&quot;.$digest.&quot;\r\n&quot;);<br> my $frame = Protocol::WebSocket::Frame-&gt;new('after connection sendi +ng');<br> $client_socket-&gt;send($frame-&gt;to_bytes);<br> # notify client that response has been sent<br> # shutdown($client_socket, 1);<br> }<br> $socket-&gt;close();</p> </body> </html>

2018-02-18 Athanasius added code and paragraph tags


In reply to Dear Monks, again socket (wbsocket server side) by ktrampas

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.