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); } }
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(); }
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(); //} }
private void UpdateLoop() { while (true) { peer.Service(); } }
// Update is called once per frame void Update() { if (PhotonPeer != null) { PhotonPeer.Service(); } }
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); }
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(); } }
/// <summary> /// Update轮询 /// </summary> /// <param name="elapseSeconds"></param> /// <param name="realElapseSeconds"></param> public void OnUpdate(float elapseSeconds, float realElapseSeconds) { if (peer != null) { peer.Service(); //photon规定必须调用,检测服务连接 } }
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(); } } } }
public override void Tick(float deltaTime) { if (peer != null) { peer.Service(); } }
// 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(); //一直向服务端发出请求 } }
private void Update() { if (null != clientpeer) { clientpeer.Service(); } }
void Update() { if (Peer != null) { Peer.Service(); } }
// 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); } }
// update peer 10 times per second IEnumerator doService() { while (true) { peer.Service(); yield return(new WaitForSeconds(0.1f)); } }
// 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"); // } }
public void Update() { if (selfPeer != null) { selfPeer.Service(); } OnUpdate(); }
// 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(); }
void Update() { //保持与服务器通信,为了避免过于频繁,我们加入了时间限制 if (peer != null && Environment.TickCount > this.nextSendTickCount) { peer.Service();//必要代码,否则无法与服务端通信 this.nextSendTickCount = Environment.TickCount + timeSpanMs; } }
// Update is called once per frame void Update() { //判断当前 peer 是否处理已连接状态 if (peer.PeerState == PeerStateValue.Connected) { } //维持 peer 与服务器端的连接 peer.Service(); }
private void DoWork() { while (_active) { _peer.SendAcksOnly(); _peer.Service(); Thread.Sleep(100); } }
void Update() { if (!IsConnect) { // 主要是防止中途断开连接时 立即重连 // TODO 这个地方重连 但没有重新登陆 无法识别客户端 m_Peer.Connect(m_ServerAddress, m_ApplicationName); } m_Peer.Service(); }
public void Service() { try { peer.Service(); } catch (Exception ex) { DebugReturn(DebugLevel.ERROR, ex.Message); DebugReturn(DebugLevel.ERROR, ex.StackTrace); } }
public bool Connect() { if (connected) { return(false); } peer.Connect("127.0.0.1:5055", "ChatServer"); while (!this.connected) { peer.Service(); } return(true); }
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; } } } }
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; }