To use sockets, consider the WebSocket interface in JavaScript. This interface enables web applications to maintain bidirectional communications with server-side processes.
To enable web applications to maintain two-way communication with server-side processes, this specification introduces the WebSocket interface.
The following are some solutions to Web Sockets:
socket = new WebSocket(url [, protocols ] )
Create a new socket using this, where parameters URL is a string for the connection and protocols is a string or array of string.
socket . send( data )
The above is used to send data.
is used to close the socket connection.
socket . close( [ code ] [, reason ] )
The following returns the URL used to establish the connection.
socket . url
The above is the detailed content of How to use sockets in JavaScript/HTML?. For more information, please follow other related articles on the PHP Chinese website!