Skip to content

Commit

Permalink
2.4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
noear committed Feb 27, 2024
1 parent c7e4759 commit b048c39
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions javascript/socketd-examples/demo02-node-ws/_broker.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@

const {SocketD} = require('@noear/socket.d');
const {BrokerListener} = require("@noear/socket.d/broker/BrokerListener");
const {BrokerFragmentHandler} = require("@noear/socket.d/broker/BrokerFragmentHandler");
const {EventListener} = require("@noear/socket.d/transport/core/Listener");
const {StringEntity} = require("@noear/socket.d/transport/core/Entity");

async function main() {
let server = SocketD.createServer("sd:ws")
.config(c => c.port(8602).fragmentHandler(new BrokerFragmentHandler))
.listen(new BrokerListener())
.config(c => c.port(8602).fragmentHandler(SocketD.newBrokerFragmentHandler()))
.listen(SocketD.newBrokerListener())
.start();


await SocketD.createClient("sd:ws://127.0.0.1:8602?@app1")
.listen(new EventListener().doOn("hello", (s, m) => {
s.reply(m, new StringEntity("me too!"));
.listen(SocketD.newEventListener().doOn("hello", (s, m) => {
s.reply(m, SocketD.newEntity("me too!"));
}))
.openOrThow();

let session2 = await SocketD.createClient("sd:ws://127.0.0.1:8602?@app2")
.openOrThow();

let r = await session2.sendAndRequest("hello", new StringEntity("hi").at("app1")).await();
let r = await session2.sendAndRequest("hello", SocketD.newEntity("hi").at("app1")).await();
console.info(r.dataAsString());
}

0 comments on commit b048c39

Please sign in to comment.