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
- Host: GitHub
- URL: https://github.com/fadilxcoder/websocket-php-html
- Owner: fadilxcoder
- Created: 2022-08-30T19:25:29.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-09-08T18:21:09.000Z (over 3 years ago)
- Last Synced: 2025-01-04T19:23:26.618Z (over 1 year ago)
- Topics: cli, client-server, html, notes, php, poc, websocket
- Language: PHP
- Homepage:
- Size: 58.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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)
