PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Adeleye Ayodeji   Simple PHP Chat with Websocket   index.php   Download  
File: index.php
Role: Auxiliary script
Content type: text/plain
Description: Configuration script
Class: Simple PHP Chat with Websocket
Implements a chat system using Websockets
Author: By
Last change:
Date: 21 hours ago
Size: 924 bytes
 

Contents

Class file image Download
<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>PHP Web Socket</title>
    </head>

    <body>
        <div>
            <button onclick="sendMessage()">Send Message</button>
        </div>
        <script>
        var conn = new WebSocket('ws://localhost:8080');
        conn.onopen = function(e) {
            console.log("Connection established!");
        };
        //check if connection error
        conn.onerror = function(e) {
            console.log("Connection error!");
        };

        conn.onmessage = function(e) {
            console.log(e.data);
        };

        function sendMessage() {
            conn.send('Hello World!');
            console.log('Message sent!');
        }
        </script>
    </body>

</html>