Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Socket connection with Perl (server side) and HTML web page.

by sectokia (Pilgrim)
on Feb 23, 2023 at 23:22 UTC ( [id://11150566]=note: print w/replies, xml ) Need Help??


in reply to Socket connection with Perl (server side) and HTML web page.

A web browser client can only run javascript given by the server in the HTML severed. Javascript does not allow raw access to sockets, it only allows certain HTTP use and certain protocols like websockets.

HTTP is limited to a client request and a server response (a server cannot just send to a client - the client has to request it i.e. ‘fetch’ .

To do a HTTP fetch in javascript use the fetch api (https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) which will be a http request to your server.

If you need the server to be able to push data to the client - you will need to use web sockets (https://developer.mozilla.org/en-US/docs/Web/API/WebSocket). In this case the server would server over http javascript that tells the client to open a websocket to be able to receive from server. on the perl side you would then need a websocket server (https://metacpan.org/pod/Net::WebSocket::Server) in addition to the http server.

  • Comment on Re: Socket connection with Perl (server side) and HTML web page.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11150566]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-25 16:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found