Jump to content

Search the Community

Showing results for tags 'websockets'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 4 results

  1. I’m currently trying to building a websocket widget, using node package manager(NPM),WAMPserver and electronjs. the package was well installed because when i start it it works. It log into the console But i dont know how i can handle it with html on wamp server . it seems electronjs is not working for wamp and websocket.
  2. I'm currently trying to building a websocket widget, using node package manager(NPM),WAMPserver and electronjs. the package was well installed because when i start it it works. It log into the console But i dont know how i can handle with html. it seems electronjs is not working fow wamp and websocket
  3. I have a running chat application in my website. It is implemented using websockets, php and is working fine. The problem is whenever i send a message to single user it broadcasts that message to all users currently connected to my website. It will be really helpful if someone can tell me how to get the unique id of each user when someone connects to our app. If i can get the userid of the current logged in chat user that would solve my problem but i am unable to retrieve that userid when the user connects (open state of websocket). I can get the userid when the connection is made but I need the userid before the connection happens. When the connecation occurs it assigns its own ids to the connected users in a serial manner(1,2,3..,n). <?php // prevent the server from timing out set_time_limit(0); // include the web sockets server script (the server is started at the far bottom of this file) require 'class.PHPWebSocket.php'; // when a client sends data to the server function wsOnMessage($clientID, $message, $messageLength, $binary) { global $Server; $ip = long2ip( $Server->wsClients[$clientID][6] ); // check if message length is 0 if ($messageLength == 0) { $Server->wsClose($clientID); return; } //Send the message to everyone but the person who said it foreach ( $Server->wsClients as $id => $client ) if ( $id != $clientID ) $Server->wsSend($id, "Visitor $clientID ($ip) said "$message""); } // when a client connects function wsOnOpen($clientID) { global $Server; $ip = long2ip( $Server->wsClients[$clientID][6] ); $Server->log( "$ip ($clientID) has connected." ); //Send a join notice to everyone but the person who joined foreach ( $Server->wsClients as $id => $client ) if ( $id != $clientID ) $Server->wsSend($id, "Visitor $clientID ($ip) has joined the room."); } // when a client closes or lost connection function wsOnClose($clientID, $status) { global $Server; $ip = long2ip( $Server->wsClients[$clientID][6] ); $Server->log( "$ip ($clientID) has disconnected." ); //Send a user left notice to everyone in the room foreach ( $Server->wsClients as $id => $client ) $Server->wsSend($id, "Visitor $clientID ($ip) has left the room."); } // start the server $Server = new PHPWebSocket(); $Server->bind('message', 'wsOnMessage'); $Server->bind('open', 'wsOnOpen'); $Server->bind('close', 'wsOnClose'); // for other computers to connect, you will probably need to change this to your LAN IP or external IP, // alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME'])) $Server->wsStartServer('127.0.0.1', 9300); ?> <!doctype html> <html> <head> <meta charset='UTF-8' /> <style> input, textarea {border:1px solid #CCC;margin:0px;padding:0px} #body {max-width:800px;margin:auto} #log {width:100%;height:400px} #message {width:100%;line-height:20px} </style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script src="fancywebsocket.js"></script> <script> var Server; function log( text ) { $log = $('#log'); //Add text to log $log.append(($log.val()?"n":'')+text); //Autoscroll $log[0].scrollTop = $log[0].scrollHeight - $log[0].clientHeight; } function send( text ) { Server.send( 'message', text ); } $(document).ready(function() { log('Connecting...'); Server = new FancyWebSocket('ws://127.0.0.1:9300'); $('#message').keypress(function(e) { if ( e.keyCode == 13 && this.value ) { log( 'You: ' + this.value ); send( this.value ); $(this).val(''); } }); //Let the user know we're connected Server.bind('open', function() { log( "Connected." ); }); //OH NOES! Disconnection occurred. Server.bind('close', function( data ) { log( "Disconnected." ); }); //Log any messages sent from server Server.bind('message', function( payload ) { log( payload ); }); Server.connect(); }); </script> </head> <body> <div id='body'> <textarea id='log' name='log' readonly='readonly'></textarea><br/> <input type='text' id='message' name='message' /> </div> </body> </html>
  4. I've finally got the time to learn web sockets and have choosen to use: http://socketo.me/docs/push to do so. It all works perfectly fine without SSL. The moment it's enabled the client javascript will not connect and will output "WebSocket opening handshake timed out". I've tried the server with and without the TLS options. client.html, post.php, server.php <script type="text/javascript" src="autobahn.js"></script> <script> var conn = new ab.Session('wss://domain.com:8443', function() { console.log('Connected'); conn.subscribe('kittensCategory', function(topic, data) { // This is where you would add the new article to the DOM (beyond the scope of this tutorial) console.log('New article published to category "' + topic + '" : ' + data.title); }); }, function() { console.warn('WebSocket connection closed'); }, {'skipSubprotocolCheck': true} ); </script> <?php require dirname(__DIR__) . '/socket/vendor/autoload.php'; // post.php ??? // This all was here before ;) $entryData = array( 'category' => 'kittensCategory' , 'title' => 'My Impressive Title' , 'article' => 'Just me the best, nothing new!' , 'when' => time() ); // This is our new stuff $context = new ZMQContext(); $socket = $context->getSocket(ZMQ::SOCKET_PUSH, 'my pusher'); $socket->connect("tcp://localhost:5555"); $socket->send(json_encode($entryData)); echo 'All Sent!'; <?php require dirname(__DIR__) . '/socket/vendor/autoload.php'; use Ratchet\ConnectionInterface; use Ratchet\Wamp\WampServerInterface; class Pusher implements WampServerInterface { /** * A lookup of all the topics clients have subscribed to */ protected $subscribedTopics = array(); public function onSubscribe(ConnectionInterface $conn, $topic) { echo 'Subbed'; $this->subscribedTopics[$topic->getId()] = $topic; } /** * @param string JSON'ified string we'll receive from ZeroMQ */ public function onBlogEntry($entry) { echo 'Hello!'; $entryData = json_decode($entry, true); // If the lookup topic object isn't set there is no one to publish to if (!array_key_exists($entryData['category'], $this->subscribedTopics)) { return; } $topic = $this->subscribedTopics[$entryData['category']]; // re-send the data to all the clients subscribed to that category $topic->broadcast($entryData); } /* The rest of our methods were as they were, omitted from docs to save space */ //public function onSubscribe(ConnectionInterface $conn, $topic) { // } public function onUnSubscribe(ConnectionInterface $conn, $topic) { } public function onOpen(ConnectionInterface $conn) { } public function onClose(ConnectionInterface $conn) { } public function onCall(ConnectionInterface $conn, $id, $topic, array $params) { // In this application if clients send data it's because the user hacked around in console $conn->callError($id, $topic, 'You are not allowed to make calls')->close(); } public function onPublish(ConnectionInterface $conn, $topic, $event, array $exclude, array $eligible) { // In this application if clients send data it's because the user hacked around in console $conn->close(); } public function onError(ConnectionInterface $conn, \Exception $e) { } } $loop = React\EventLoop\Factory::create(); $pusher = new Pusher; // Listen for the web server to make a ZeroMQ push after an ajax request $context = new React\ZMQ\Context($loop); $pull = $context->getSocket(ZMQ::SOCKET_PULL); $pull->bind('tcp://127.0.0.1:5555'); // Binding to 127.0.0.1 means the only client that can connect is itself $pull->on('message', array($pusher, 'onBlogEntry')); // Set up our WebSocket server for clients wanting real-time updates $webSock = new React\Socket\Server('0.0.0.0:8443', $loop, array( 'tls' => array( 'local_cert' => 'cert.pem', 'local_pk' => 'private.key', // path to your server private key, 'verify_peer' => FALSE ))); // Binding to 0.0.0.0 means remotes can connect $webServer = new Ratchet\Server\IoServer( new Ratchet\Http\HttpServer( new Ratchet\WebSocket\WsServer( new Ratchet\Wamp\WampServer( $pusher ) ) ), $webSock ); $loop->run();
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.