casino-server icon indicating copy to clipboard operation
casino-server copied to clipboard

About websockets

Open terhoraj opened this issue 7 years ago • 6 comments

Can you lighten me up with few words how do I actually can use websockets from mobile side for example android.

I only need to know about for instance, whats the actual "api" address for websocket protocol and is it ws:// schema starting. I'm new to websocket and I don't want to know all by asking, I'm going to do my own research.

Web client example seems pretty clear to me but it's socket.io at your image. Socket.io is similar to websockets or completely different method?

Thanks for awesome server platform!

terhoraj avatar May 04 '17 05:05 terhoraj

@terhoraj you can check this project for the java websocket library: https://github.com/koush/AndroidAsync

Obj-C websocket library: https://github.com/facebook/SocketRocket

C# websocket client library: https://github.com/Quobject/SocketIoClientDotNet

floatinghotpot avatar May 04 '17 13:05 floatinghotpot

I have now tried AndroidAsync library websocket part with tons of differently formed url:s the the server and last result was handshake error. No luck. Web GUI works as far as login so I believe that side is fine.

terhoraj avatar May 04 '17 18:05 terhoraj

Does anyone reading this have solved this websocket side for example mobile side since when I look at the code I don't even see implementation for websocket's.

terhoraj avatar May 16 '17 17:05 terhoraj

I find a better C# library for socket.io: https://github.com/Quobject/SocketIoClientDotNet

floatinghotpot avatar May 24 '17 00:05 floatinghotpot

Using nuget to add the .NET library to your C# project

nuget SocketIoClientDotNet

Then write C# code to connect and send request to casino server.

using System;
using Quobject.SocketIoClientDotNet.Client;

namespace iotest
{
  class MainClass
  {
    public static void Main(string[] args)
    {
      Console.WriteLine("Hello World!");

      var socket = IO.Socket("http://127.0.0.1:7000");
      socket.On(Socket.EVENT_CONNECT, () =>
      {
        Console.WriteLine("Connected.");
        socket.Emit("hello");
      });

      socket.On("notify", (data) =>
      {
        Console.WriteLine(data);
      });

      socket.On("rpc_ret", (data) =>
      {
        Console.WriteLine(data);
      });

      while (true)
      {
        string str = Console.ReadLine();
        if (str == "quit") break;
        else socket.Emit("rpc", str);
      }

      socket.Disconnect();
    }
  }
}

Run test, console output:

iMac:Debug liming$ mono test.exe
Hello World!
Connected.
{
  "uid": null,
  "e": "prompt",
  "args": {
    "fastsignup": true,
    "signup": {
      "uid": "text",
      "passwd": "text",
      "name": "text",
      "email": "email",
      "phone": "text",
      "uuid": "text"
    },
    "login": {
      "uid": "text",
      "passwd": "text"
    }
  }
}
login
{
  "err": 400,
  "ret": "invalid rpc req"
}

floatinghotpot avatar May 24 '17 00:05 floatinghotpot

Update: I've ported SocketIoClientForNet to Unity. See it here: https://github.com/floatinghotpot/socket.io-unity

floatinghotpot avatar Jun 07 '17 20:06 floatinghotpot