Beispiel #1
0
        public void Run()
        {
            if (m_Peer.Connect("127.0.0.1:4530", "ChatServer"))
            {
                Thread thread = new Thread(UpdateLoop);
                thread.IsBackground = true;
                thread.Start();

                do
                {
                    m_Peer.Service();

                    switch (m_State)
                    {
                    case GameState.Initiation:
                        break;

                    case GameState.Connected:
                        LoginToServer();
                        m_State = GameState.OnLogin;
                        break;

                    case GameState.OnLogin:
                        break;

                    case GameState.Chatting:
                        HandleChatting();
                        break;

                    case GameState.Disconnected:
                        break;
                    }
                } while (true);
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            ChatServerListener listener = new ChatServerListener();
            PhotonPeer         peer     = new PhotonPeer(listener, ConnectionProtocol.Tcp);

            //连接服务器
            peer.Connect("127.0.0.1:4520", "ChatServer");

            Console.WriteLine("Connecting...");

            while (listener.isConnected == false)
            {
                peer.Service();
            }

            Dictionary <byte, object> dict = new Dictionary <byte, object>();

            dict.Add(1, "username");
            dict.Add(2, "password");

            peer.OpCustom(1, dict, true);

            while (true)
            {
                peer.Service();
            }

            Console.ReadKey();
        }
        public ChatPeerListener(ChatClient chatClient, PlayerInfo playerInfo, string serverAddress, string applicationName)
        {
            Player = playerInfo;
            ChatClient = chatClient;
            _connected = false;
            _operations = new Dictionary<byte, IBaseOp>();
            foreach (var item in typeof(IBaseOp).Assembly.GetTypes().Where(_ => !_.IsAbstract && typeof(IBaseOp).IsAssignableFrom(_)))
            {
                var obj = (IBaseOp)Activator.CreateInstance(item);
                _operations[obj.OpCode] = obj;
            }

            _peer = new PhotonPeer(this, ConnectionProtocol.Udp);
            _peer.Connect(serverAddress, applicationName);
            while (!_connected)
            {
                _peer.Service();
            }

            var t = new Timer
            {
                Enabled = true,
                Interval = 10
            };

            t.Elapsed += (sender, args) => _peer.Service();
            t.Start();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            GameServerListener listener = new GameServerListener();

            PhotonPeer peer = new PhotonPeer(listener, ConnectionProtocol.Tcp);

            Console.WriteLine("connecting...");
            peer.Connect("127.0.0.1:4530", "GameServer");
            while (!listener.isConnected)
            {
                peer.Service();
            }

            Dictionary <byte, Object> dict = new Dictionary <byte, object>
            {
                { 1, "username" },
                { 2, "password" }
            };

            peer.OpCustom(1, dict, true);

            while (true)
            {
                peer.Service();
            }
        }
 // Update is called once per frame
 void Update()
 {
     //if (peer.PeerState == PeerStateValue.Connected)
     //{
     peer.Service();
     //}
 }
Beispiel #6
0
 private void UpdateLoop()
 {
     while (true)
     {
         peer.Service();
     }
 }
Beispiel #7
0
 // Update is called once per frame
 void Update()
 {
     if (PhotonPeer != null)
     {
         PhotonPeer.Service();
     }
 }
Beispiel #8
0
        private static bool CheckConnection(string serverAddress, string appId, ConnectionProtocol protocol)
        {
            var listner = new PhotonListener(false);
            var peer    = new PhotonPeer(listner, protocol);

            if (!peer.Connect(serverAddress, appId))
            {
                return(false);
            }

            var counter = 100;

            while (--counter > 0)
            {
                peer.Service();
                if (listner.WaitForConnection(0))
                {
                    var res = peer.PeerState == PeerStateValue.Connected;
                    peer.Disconnect();
                    return(res);
                }
                Thread.Sleep(50);
            }
            return(false);
        }
Beispiel #9
0
        private void Run(string username, string password)
        {
            this.username = username;
            this.password = password;

            peer = new PhotonPeer(this, ConnectionProtocol.Udp)
            {
                ChannelCount = 2
            };
            peer.Connect("127.0.0.1:5055", "Master");

            var timer = Stopwatch.StartNew();

            timer.Start();

            while (true)
            {
                if (timer.ElapsedMilliseconds < 50)
                {
                    continue;
                }

                peer.Service();
                timer.Restart();
            }
        }
Beispiel #10
0
 /// <summary>
 /// Update轮询
 /// </summary>
 /// <param name="elapseSeconds"></param>
 /// <param name="realElapseSeconds"></param>
 public void OnUpdate(float elapseSeconds, float realElapseSeconds)
 {
     if (peer != null)
     {
         peer.Service();     //photon规定必须调用,检测服务连接
     }
 }
Beispiel #11
0
        public void Run()
        {
            mCommandBuilder.Clear();
            while (mLoopStarted)
            {
                if (mPeer != null)
                {
                    mPeer.Service();
                }

                if (Console.KeyAvailable)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    ConsoleKeyInfo key = Console.ReadKey();
                    if (key.Key != ConsoleKey.Enter)
                    {
                        mCommandBuilder.Append(key.KeyChar);
                    }
                    else
                    {
                        Console.WriteLine();
                        string command = mCommandBuilder.ToString();
                        ExecuteCommand(command);
                        mCommandBuilder.Clear();
                    }
                }
            }
        }
Beispiel #12
0
 public override void Tick(float deltaTime)
 {
     if (peer != null)
     {
         peer.Service();
     }
 }
Beispiel #13
0
 // Update is called once per frame
 void Update()
 {
     if (peer != null)
     {
         peer.Service();
     }
 }
 // Update is called once per frame
 void Update()
 {
     if (peer != null)
     {
         peer.Service();  //一直向服务端发出请求
     }
 }
Beispiel #15
0
 private void Update()
 {
     if (null != clientpeer)
     {
         clientpeer.Service();
     }
 }
 void Update()
 {
     if (Peer != null)
     {
         Peer.Service();
     }
 }
Beispiel #17
0
 // Update is called once per frame
 void Update()
 {
     if (!isConnect)
     {
         peer.Connect(serverAddress, applicationName);
     }
     peer.Service();
 }
 private void Update()
 {
     if (!connected)
     {
         peer.Connect(serverAddress, applicationName);           //连接服务器
     }
     peer.Service();                                             //获取服务,持续调用才能接受信息
 }
 private void UpdateLoop()
 {
     while (true)
     {
         peer.Service();
         Thread.Sleep(25);
     }
 }
Beispiel #20
0
 // update peer 10 times per second
 IEnumerator doService()
 {
     while (true)
     {
         peer.Service();
         yield return(new WaitForSeconds(0.1f));
     }
 }
Beispiel #21
0
 // update peer 20 times per second
 IEnumerator doService()
 {
     while (true)
     {
         Connection.Service();
         yield return(new WaitForSeconds(0.05f));
     }
 }
    void Update()
    {
        Peer.Service();

//        if (peer.PeerState == PeerStateValue.Connected)
//        {
//            peer.Connect("127.0.0.1:5055", "MyGame1");
//	      }
    }
Beispiel #23
0
        public void Update()
        {
            if (selfPeer != null)
            {
                selfPeer.Service();
            }

            OnUpdate();
        }
Beispiel #24
0
 // Update is called once per frame
 void Update()
 {
     //if (peer.PeerState == PeerStateValue.Connected)
     //{
     //    peer.Service();//需要在Update里面一直调用该方法
     //}
     //不需要判断peer的状态
     peer.Service();//需要在Update里面一直调用该方法
 }
 void Update()
 {
     if (!connected)
     {
         Debug.Log("检测到未连接,重新连接");
         peer.Connect(serverAddress, applicationName);    //,如果服务器未连接,那么连接服务器
     }
     peer.Service();
 }
Beispiel #26
0
 void Update()
 {
     //保持与服务器通信,为了避免过于频繁,我们加入了时间限制
     if (peer != null && Environment.TickCount > this.nextSendTickCount)
     {
         peer.Service();//必要代码,否则无法与服务端通信
         this.nextSendTickCount = Environment.TickCount + timeSpanMs;
     }
 }
Beispiel #27
0
 // Update is called once per frame
 void Update()
 {
     //判断当前 peer 是否处理已连接状态
     if (peer.PeerState == PeerStateValue.Connected)
     {
     }
     //维持 peer 与服务器端的连接
     peer.Service();
 }
Beispiel #28
0
        private void DoWork()
        {
            while (_active)
            {
                _peer.SendAcksOnly();
                _peer.Service();

                Thread.Sleep(100);
            }
        }
Beispiel #29
0
 void Update()
 {
     if (!IsConnect)
     {
         // 主要是防止中途断开连接时 立即重连
         // TODO 这个地方重连 但没有重新登陆 无法识别客户端
         m_Peer.Connect(m_ServerAddress, m_ApplicationName);
     }
     m_Peer.Service();
 }
Beispiel #30
0
 public void Service()
 {
     try
     {
         peer.Service();
     }
     catch (Exception ex)
     {
         DebugReturn(DebugLevel.ERROR, ex.Message);
         DebugReturn(DebugLevel.ERROR, ex.StackTrace);
     }
 }
Beispiel #31
0
 public bool Connect()
 {
     if (connected)
     {
         return(false);
     }
     peer.Connect("127.0.0.1:5055", "ChatServer");
     while (!this.connected)
     {
         peer.Service();
     }
     return(true);
 }
Beispiel #32
0
    public static void Main()
    {
        var client = new ChatClient();
        var peer = new PhotonPeer(client, ConnectionProtocol.Tcp);

        // connect
        client.connected = false;
        peer.Connect("127.0.0.1:4530", "ChatServer");
        while (!client.connected)
        {
            peer.Service();
        }

        var buffer = new StringBuilder();
        while (true)
        {
            peer.Service();

            // read input
            if (Console.KeyAvailable)
            {
                ConsoleKeyInfo key = Console.ReadKey();
                if (key.Key != ConsoleKey.Enter)
                {
                    // store input
                    buffer.Append(key.KeyChar);
                }
                else
                {
                    // send to server
                    var parameters = new Dictionary<byte, object> { { 1, buffer.ToString() } };
                    peer.OpCustom(1, parameters, true);
                    buffer.Length = 0;
                }
            }
        }
    }
Beispiel #33
0
        private static bool CheckConnection(string serverAddress, string appId, ConnectionProtocol protocol)
        {
            var listner = new PhotonListener(false);
            var peer = new PhotonPeer(listner, protocol);

            if (!peer.Connect(serverAddress, appId))
            {
                return false;
            }

            var counter = 100;
            while (--counter > 0)
            {
                peer.Service();
                if (listner.WaitForConnection(0))
                {
                    var res = peer.PeerState == PeerStateValue.Connected;
                    peer.Disconnect();
                    return res;
                }
                Thread.Sleep(50);
            }
            return false;
        }