Answer the question
In order to leave comments, you need to log in
How to connect to a channel via Websocket?
I'm making a simple chat application in Xamarin (client) and Laravel (server)
Set up websockets on the server using laravel websockets library and pusher
Here is my event NewMessage
class NewMessage implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $message;
public function __construct($message)
{
$this->message = $message;
}
public function broadcastOn()
{
return new Channel('chat-room');
}
public function broadcastWith(): array
{
return [
"message" => $this->message
];
}
}
Broadcast::channel('chat-room', function ($message) {
return true;
});
data: "{"socket_id":"249965922.74383293","activity_timeout":30}"
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
using WebSocketSharp;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Con1();
}
private static async Task Con1()
{
using (WebSocketSharp.WebSocket web = new WebSocketSharp.WebSocket("ws://192.168.0.105:6001/app/ABCDEFG"))
{
web.OnMessage += WsOnMEssage;
web.Connect();
web.Ping();
Console.ReadKey();
}
}
private static void WsOnMEssage(object sender, MessageEventArgs e)
{
Console.WriteLine(e.Data);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question