Esempio n. 1
0
        private IEnumerator Start()
        {
            mHostIp = NetworkUtil.GetAddressIP();

            mSocketServer = FlexiSocket.Create(1366, Protocols.BodyLengthPrefix, false);
            mSocketServer.ClientConnected += delegate(ISocketClientToken client)
            {
                Log.i("OnClientConnected ID:{0} Count:{1}", client.ID, mSocketServer.Clients.Count);
            };
            mSocketServer.SentToClient += delegate(bool success, ISocketClientToken client)
            {
                if (success)
                {
                }
            };

            mSocketServer.ReceivedFromClient += delegate(ISocketClientToken client, byte[] message)
            {
                SocketMsg msg = SerializeHelper.FromProtoBuff <SocketMsg>(message);
                mMessage = msg.msgId + ":" + msg.ToEventID;
                if (!string.IsNullOrEmpty(msg.Msg))
                {
                    mMessage += ":" + msg.Msg;
                }
                Log.i("OnReceivedFromClient:{0}", mMessage);
                mMsgQueue.Enqueue(msg);
            };

            mSocketServer.ClientDisconnected += delegate(ISocketClientToken client)
            {
            };
            mSocketServer.StartListen(10);

            yield return(0);
        }
Esempio n. 2
0
        private IEnumerator Start()
        {
//			this.Sequence().Delay();

            var delayNode = new DelayNode(1.0f);

            delayNode.OnBeganCallback = () => Log.I("first began");
            delayNode.OnEndedCallback = () => Log.I("first ended");

            var delayNode2 = new DelayNode(1.0f);

            delayNode2.OnBeganCallback = () => Log.I("second began");
            delayNode2.OnEndedCallback = () => Log.I("second ended");

            yield return(SequenceNode.Allocate(delayNode, delayNode2).Execute());

            yield return(QWait.ForSeconds(1.0f));

            Log.I("from seconds");

            mHostIp = NetworkUtil.GetAddressIP();

            mSocketServer = FlexiSocket.Create(1366, Protocols.BodyLengthPrefix, false);
            mSocketServer.ClientConnected += delegate(ISocketClientToken client)
            {
                Log.I("OnClientConnected ID:{0} Count:{1}", client.ID, mSocketServer.Clients.Count);
            };
            mSocketServer.SentToClient += delegate(bool success, ISocketClientToken client)
            {
                if (success)
                {
                }
            };

            mSocketServer.ReceivedFromClient += delegate(ISocketClientToken client, byte[] message)
            {
                SocketMsg msg = SerializeHelper.FromProtoBuff <SocketMsg>(message);
                mMessage = msg.msgId + ":" + msg.ToEventID;
                if (!string.IsNullOrEmpty(msg.Msg))
                {
                    mMessage += ":" + msg.Msg;
                }
                Log.I("OnReceivedFromClient:{0}", mMessage);
                mMsgQueue.Enqueue(msg);
            };

            mSocketServer.ClientDisconnected += delegate(ISocketClientToken client) {};
            mSocketServer.StartListen(10);

            yield return(0);
        }
Esempio n. 3
0
    // Use this for initialization
    private IEnumerator Start()
    {
        _server = FlexiSocket.Create(1366, Protocols.BodyLengthPrefix, false);
        _server.ClientConnected    += OnClientConnected;
        _server.ClientDisconnected += OnClientDisconnected;
        _server.ReceivedFromClient += OnReceivedFromClient;
        _server.SentToClient       += OnSentToClient;
        _server.StartListen(10);

        while (_server.IsListening)
        {
            yield return(new WaitForSeconds(Random.Range(1, 5)));

            foreach (var client in _server.Clients)
            {
                client.Send(Encoding.UTF8.GetBytes("Random message"));
            }
        }
    }