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?? |
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.
In Section
Seekers of Perl Wisdom
|
|