Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About websockets #20

Open
terhoraj opened this issue May 4, 2017 · 6 comments
Open

About websockets #20

terhoraj opened this issue May 4, 2017 · 6 comments

Comments

@terhoraj
Copy link

terhoraj commented May 4, 2017

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!

@floatinghotpot
Copy link
Owner

floatinghotpot commented May 4, 2017

@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

@terhoraj
Copy link
Author

terhoraj commented May 4, 2017

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
Copy link
Author

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.

@floatinghotpot
Copy link
Owner

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

@floatinghotpot
Copy link
Owner

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants