drashland/wocket

Error when start socket channel

mtegarsantosa opened this issue · 8 comments

I just upgrade deno to v1.2.0 and updating all cached versions to the latest. When i start sockets again, this happened.

[ERROR]: Property 'onMessage' does not exist on type 'SocketServer'

also..

[ERROR]: Expected 1 arguments, but got 2. },{ which is related to:

const socketServer = new SocketServer();
socketServer.run({
  hostname: "localhost",
  port: 3000
},{
  reconnect: false
});

which previously worked.

Hi @arsandev,

The API changed. If you're using onMessage(), change it to on().

When creating a socket server, use the following:

const socketServer = new SocketServer({
  reconnect: false
});

socketServer.run({
  hostname: "localhost",
  port: 3000
});

Let me know how it goes.

Socket server automatically runs on port 1557 with this following.

// Create the socket server
const socketServer = new SocketServer({
  reconnect: false
});

and

// Create "Channel 1" so that clients can send messages to it
socketServer
  .on("Channel 1", (packet: any) => {
    console.log(packet);
    console.log("Sending a message back to the client.");
    // Send messages to all clients listening to "Channel 1"
    socketServer.to(
      "Channel 1",
      `Message received! You sent "${packet.message}" as the message.`,
    );
  });

Now the problem is to connect from client.
I use this example.

/index.html

import SocketClient from 'https://cdn.jsdelivr.net/gh/drashland/sockets-client@latest/client.js';
    const socketClient = new SocketClient({
      hostname: 'localhost',
      port: 1557
    });

I get this.
image

Hey @arsandev , can you show the full contents of your file that is starting the socket server? The error message you're seeing makes me think there is no socket server running, or any endpoint running on localhost:1557

I followed on https://github.com/drashland/sockets/blob/master/example_apps/browser_console/app.ts

socket.ts

import { SocketServer } from "https://deno.land/x/sockets@master/mod.ts";

// Create the socket server
const socketServer = new SocketServer({
  reconnect: false
});
console.log(
  `Socket server started on ws://${socketServer.hostname}:${socketServer.port}`,
);

// Listen for connections to the socket server
socketServer.on("connection", () => {
  console.log("A user connected.");
});

// Listen for disconnections from the socket server
socketServer.on("disconnect", () => {
  console.log("A user disconnected.");
});

// Create "Channel 1" so that clients can send messages to it
socketServer
  .on("Channel 1", (packet: any) => {
    console.log(packet);
    console.log("Sending a message back to the client.");
    // Send messages to all clients listening to "Channel 1"
    socketServer.to(
      "Channel 1",
      `Message received! You sent "${packet.message}" as the message.`,
    );
  });

Nothing is running on port 1557. To be sure, I changed the port to 1234

const socketServer = new SocketServer();
socketServer.run({
  hostname: "localhost",
  port: 1234,
});

Results:
image

Hey, so you’ve got to start your socket server after instantiating it:

socketServer.run({ hostname: “localhost”, port: 1557 })

Also that example doesn’t currently work, I made a pr earlier that actually fixed the chat example app so you can use that as a reference: https://github.com/drashland/sockets/pull/61

It still doesn't work for me. all example_apps (master and v0.x branch) still don't work. I've tried making a pull request but haven't been able to solve this yet. I'm optimistic that this project can reach the stable version and I can contribute to the limits that I understand. Good job all of you!

Hi @arsandev ,

We're currently working towards v0.5.0 which has better documentation on building a chat app and understanding the inner workings of the framework. If you want, you can read the documentation in our staging environment right now: https://drash.land/sockets/staging