Пример #1
0
    void Start()
    {
        // The current state is Login
        State = ChatStates.Login;

        // Change an option to show how it should be done
        SocketOptions options = new SocketOptions();
        options.AutoConnect = false;
        
        // Create the Socket.IO manager
        Manager = new SocketManager(new Uri("http://chat.socket.io/socket.io/"), options);

        // Set up custom chat events
        Manager.Socket.On("login", OnLogin);
        Manager.Socket.On("new message", OnNewMessage);
        Manager.Socket.On("user joined", OnUserJoined);
        Manager.Socket.On("user left", OnUserLeft);
        Manager.Socket.On("typing", OnTyping);
        Manager.Socket.On("stop typing", OnStopTyping);

        // The argument will be an Error object.
        Manager.Socket.On(SocketIOEventTypes.Error, (socket, packet, args) => Debug.LogError(string.Format("Error: {0}", args[0].ToString())));

        // We set SocketOptions' AutoConnect to false, so we have to call it manually.
        Manager.Open();
    }
 public void Connect()
 {
     BestHTTP.SocketIO.SocketOptions options = new BestHTTP.SocketIO.SocketOptions();
     options.ConnectWith = BestHTTP.SocketIO.Transports.TransportTypes.WebSocket;
     manager             = new BestHTTP.SocketIO.SocketManager(new Uri(APIConfiguration.HostURL + APIConfiguration.SocketIORoute), options);
     manager.Socket.On(BestHTTP.SocketIO.SocketIOEventTypes.Connect, OnConnected);
 }
Пример #3
0
    void Start()
    {
        // Change an option to show how it should be done
        SocketOptions options = new SocketOptions();
        options.AutoConnect = false;

        // Create the SocketManager instance
        var manager = new SocketManager(new Uri("http://io.weplay.io/socket.io/"), options);

        // Keep a reference to the root namespace
        Socket = manager.Socket;

        // Set up our event handlers.
        Socket.On(SocketIOEventTypes.Connect, OnConnected);
        Socket.On("joined", OnJoined);
        Socket.On("connections", OnConnections);
        Socket.On("join", OnJoin);
        Socket.On("move", OnMove);
        Socket.On("message", OnMessage);
        Socket.On("reload", OnReload);

        // Don't waste cpu cycles on decoding the payload, we are expecting only binary data with this event,
        //  and we can access it through the packet's Attachments property.
        Socket.On("frame", OnFrame, /*autoDecodePayload:*/ false);

        // Add error handler, so we can display it
        Socket.On(SocketIOEventTypes.Error, OnError);

        // We set SocketOptions' AutoConnect to false, so we have to call it manually.
        manager.Open();

        // We are connecting to the server.
        State = States.Connecting;
    }
Пример #4
0
 /// <summary>
 /// Constructor to create a SocketManager instance.
 /// </summary>
 public SocketManager(Uri uri, SocketOptions options)
 {
     Uri           = uri;
     Options       = options;
     State         = States.Initial;
     PreviousState = States.Initial;
     Encoder       = SocketManager.DefaultEncoder;
 }
Пример #5
0
 /// <summary>
 /// Constructor to create a SocketManager instance.
 /// </summary>
 public SocketManager(string ip, SocketOptions options)
 {
     Uri           = new Uri("http://" + ip + HopeRun.GlobalManager.PORTAL + "/socket.io/");
     Options       = options;
     State         = States.Initial;
     PreviousState = States.Initial;
     Encoder       = SocketManager.DefaultEncoder;
 }
Пример #6
0
 public SocketManager(Uri uri, SocketOptions options)
 {
     this.Uri           = uri;
     this.Options       = options;
     this.State         = SocketManager.States.Initial;
     this.PreviousState = SocketManager.States.Initial;
     this.Encoder       = SocketManager.DefaultEncoder;
 }
 public void Connect()
 {
     if (!IsConnected)
     {
         string uri = "";
         // #if UNITY_EDITOR
         //     uri = "http://localhost:1337/socket.io/";
         // #else
         uri = "http://blockparty-server.herokuapp.com/socket.io/";
         // #endif
         BestHTTP.SocketIO.SocketOptions options = new BestHTTP.SocketIO.SocketOptions();
         options.ConnectWith = BestHTTP.SocketIO.Transports.TransportTypes.WebSocket;
         manager             = new BestHTTP.SocketIO.SocketManager(new Uri(uri), options);
         manager.Socket.On(BestHTTP.SocketIO.SocketIOEventTypes.Connect, OnConnected);
     }
 }
Пример #8
0
 /// <summary>
 /// Constructor to create a SocketManager instance.
 /// </summary>
 public SocketManager(Uri uri, SocketOptions options)
 {
     Uri = uri;
     Options = options;
     State = States.Initial;
     PreviousState = States.Initial;
     Encoder = SocketManager.DefaultEncoder;
 }