AnnouncementsMatrixEventsFunnyVideosMusicAncapsTechnologyEconomicsPrivacyGIFSCringeAnarchyFilmPicsThemesIdeas4MatrixAskMatrixHelpTop Subs
2

It is not better than o3-mini-high. In fact I should test it against deepseek here since that's what we have.

@bot. Could you show me an example in nodeJS of http2 of a server pushing objects to the client over time. This should be server initiated. I would like to see both the server code and the client code.

Comment preview
[-]bot1(+1|0)
Details

Okay, I need to help the user by providing Node.js examples for an HTTP/2 server pushing data to a client. The user wants both server and client code.

First, I'll start by setting up the server using the 'http2' module. I'll create a server that listens on port 8080. When a request is made, the server will initiate a push stream. I'll send some initial data, then simulate sending more data over time using a setInterval function. This way, the client will receive data periodically.

For the client side, I'll use the 'http2' module to connect to the server. I'll set up event listeners to handle incoming data, when a stream ends, and any errors. The client will connect to the server and request the root path, which will trigger the server to start pushing data.

I'll make sure to include both code examples, one for the server and one for the client. I'll also add comments to explain key parts of the code, like where the data is being sent and how the intervals work.

Finally, I'll suggest that the user can modify the data and timing as needed, which should help them adapt the example to their specific use case.

Hey! I see you're looking for Node.js examples of HTTP/2 server pushing data to a client. Here's a quick example of how you can implement this:

Server Code:

const http2 = require('http2');
const server = http2.createServer();

server.on('request', (req, res) => {
  if (req.method === 'GET' && req.url === '/push') {
    // Initiate a push stream
    const pushStream = server.pushStream(res, {
      ':path': '/data',
      ':method': 'GET'
    });

    // Send initial data
    pushStream.sendHeader();
    pushStream.write('Initial data');

    // Simulate sending data over time
    const interval = setInterval(() => {
      pushStream.write(`New data at ${new Date().toLocaleTimeString()}`);
    }, 5000);

    // Clean up
    pushStream.on('close', () => {
      clearInterval(interval);
    });
  }
});

server.listen(8080, () => {
  console.log('HTTP/2 server is running on port 8080');
});

Client Code:

const http2 = require('http2');
const client = http2.connect('http://localhost:8080');

client.on('connect', (session) => {
  const req = session.request({
    ':method': 'GET',
    ':path': '/push'
  });

  req.on('response', (headers, stream) => {
    stream.on('data', (chunk) => {
      console.log('Received:', chunk.toString());
    });

    stream.on('end', () => {
      console.log('Stream ended');
    });
  });

  req.end();
});

This example sets up a basic HTTP/2 server that pushes data to the client every 5 seconds. The client connects to the server and listens for incoming data. You can modify the data being sent and the timing to suit your needs!

[-]x0x7
1(+1|0)

I'm not going to rank that very high. It mixed up some nodeJS semantics for http1.1 and http2. It did understand to use pushStream faster than o3 or grok did which is cool. It didn't make a new pushStream per object send (bad). It didn't end the server side res (and res is semantics that shouldn't exist in node:http2 space).

I'm shit talking it but really none of them did well. I think AI doesn't understand http2+nodeJS and also that http2 is really not ready for what I want to use it for. Not only is there very little existing code that is compatible with it in nodeJS, but nodeJS is ahead of all the other languages and so it only gets worse or outright unsupported in other languages. Zig I know has no libraries that I can find. Erlang and Python do seem to have something.

I'm trying to set up a microservice inerop orchestration thing, so what I make should be compatible with as many languages as possible.

I've done http1.1 polling, slow. I've assessed if http2 is a good option (not the best). The other things to assess are websockets (might be less universal than you think. I'm familiar. Honestly it's a good fit but they are tedious and I want to try new things), raw tcp to send hints to "poll early", hanging the http1.1 response and reopening on a timeout or sending keep-alive empty arrays, and last just doing raw tcp for everything (honestly not that hard).

Gee, what if humanity just stopped trying to build protocols on top of protocols and realized that TCP is enough. I've had that mentality before. Maybe I should reƫmbrace the light. Every protocol we build on it is just limiting, and TCP is not that complicated to work with directly. Opposite really.

[-]x0x7
1(+1|0)

o3-mini-high was not perfect and needed some coaching to give me the example. grok 3 needed more. We'll see what the bot here gives me in a second. In this case the RAG should be either neutral or a detriment because I don't really have anything in the RAG to cover this so it is going to get a little bit of irrelevant text in the request.