An open API service indexing awesome lists of open source software.

https://github.com/fadilxcoder/websocket-php-html

PHP websocket - Client / Server
https://github.com/fadilxcoder/websocket-php-html

cli client-server html notes php poc websocket

Last synced: about 1 year ago
JSON representation

PHP websocket - Client / Server

Awesome Lists containing this project

README

          

# Notes (SERVER)

- Install dependencies - `composer install`
- Create `src/socket.php`

```php
clients = new \SplObjectStorage;
}

public function onOpen(ConnectionInterface $conn)
{
....
}

public function onMessage(ConnectionInterface $from, $msg)
{
....
}

public function onClose(ConnectionInterface $conn)
{
....
}

public function onError(ConnectionInterface $conn, \Exception $e)
{
....
}
}
```

- Create `run` php bash script - Executable in CLI

```php
#!/usr/bin/env php

run();
```

- **NB** Run script using **CLI - Command Prompt** (Security measures)
- RUN `php run` to launch local web socket server
---

# Notes (CLIENT)

```js

// Create a new WebSocket.

//var socket = new WebSocket('ws://127.0.0.1:8088');
var socket = new WebSocket("ws://192.168.100.XX:8088");

var message = document.getElementById('message');

function transmitMessage() {
socket.send( message.value );
}

socket.onmessage = function(e) {
alert( e.data );
}
```

URL : http://localhost/websocket/ - use local tunnel / ngrok (Will work on same network)