Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your solution of a HTTP server running on a special port is exactly the solution I ended up with when faced with a similar problem. The PHP app simply uses <a href="http://www.php.net/manual/en/ref.curl.php" rel="nofollow noreferrer">curl</a> to <code>POST</code> to the Node server, which then pushes a message out to socket.io.</p> <p><strong>However</strong>, your HTTP server implementation is broken. The <code>data</code> event is a <a href="http://nodejs.org/api/stream.html" rel="nofollow noreferrer"><code>Stream</code></a> event; Streams <strong>do not emit messages</strong>, they emit chunks of data. In other words, the request entity data may be split up and emitted in two chunks.</p> <p>If the <code>data</code> event emitted a partial chunk of data, <code>JSON.parse</code> would almost assuredly throw an exception, and your Node server would crash.</p> <p>You either need to manually <a href="https://stackoverflow.com/a/14540576/201952">buffer data</a>, or (my recommendation) use a more robust framework for your HTTP server like <a href="http://expressjs.com" rel="nofollow noreferrer">Express</a>:</p> <pre><code>var express = require('express'), forumserver = express(); forumserver.use(express.bodyParser()); // handles buffering and parsing of the // request entity for you forumserver.post('/post/:threadid', function(req, res) { io.sockets.in(req.params.threadid).emit('new-post', req.body.content); res.send(204); // HTTP 204 No Content (empty response) }); forumserver.listen(82); </code></pre> <p>PHP simply needs to post to http&#8203;://localhost:82/post/1234 with an entity body containing <code>content</code>. (JSON, URL-encoded, or multipart-encoded entities are acceptable.) Make sure your firewall blocks port 82 on your public interface.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload