Esempio n. 1
0
 public void Connect(string endPoint)
 {
     if (!_peer.Connect(endPoint, RealtimeVersion.Current))
     {
         OnConnectFailed(endPoint);
     }
 }
Esempio n. 2
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();
            }
        }
Esempio n. 3
0
 void Start()
 {
     //这里使用udp协议,udp不稳定的问题已在photon修复
     //通过Listender接收服务器的响应
     m_peer = new PhotonPeer(this, ConnectionProtocol.Udp);
     m_peer.Connect("192.168.10.84:5055", "MyGame1");//服务器端口 应用名
 }
Esempio n. 4
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();
        }
 // Use this for initialization
 void Start()
 {
     peer = new PhotonPeer(this, ConnectionProtocol.Udp);
     bool isConnected = peer.Connect("10.0.0.115:5055", "StarCollectorServer");
     Debug.Log(isConnected);
     StartCoroutine(DoService());
 }
Esempio n. 6
0
 // Use this for initialization
 void Start()
 {
     //通过Listender接受服务器端的响应
     Debug.Log("Wait to Connect");
     peer = new PhotonPeer(this, ConnectionProtocol.Udp);
     peer.Connect("47.101.223.4:5055", "MyGame1");   //47.101.223.4
 }
Esempio n. 7
0
        protected void Connect(string address, string playerName)
        {
            this.playerName = playerName;

            selfPeer = new PhotonPeer(this, ConnectionProtocol.Udp);
            selfPeer.Connect(address, "Poker");
        }
Esempio n. 8
0
 private void Awake()
 {
     _instance = this;
     peer      = new PhotonPeer(this, protocol);
     peer.Connect(serverAddress, ApplicationName);
     DontDestroyOnLoad(this.gameObject);
 }
Esempio n. 9
0
    public void Connect()
    {
        try
        {
            string serverAddress = IANTGame.ServerAddress;
#if UNITY_WEBGL && !UNITY_EDITOR
            peer = new PhotonPeer(this, ConnectionProtocol.WebSocketSecure);
            peer.SocketImplementation = typeof(SocketWebTcp);
            serverAddress             = "wss://" + serverAddress + ":" + IANTGame.WebSocketPort;
#else
            peer           = new PhotonPeer(this, ConnectionProtocol.Udp);
            serverAddress += ":" + IANTGame.UdpPort;
#endif
            if (!peer.Connect(serverAddress, IANTGame.ServerName))
            {
                IANTGame.Service.DebugReturn(DebugLevel.ERROR, "Connect fail in peer.Connect");
                IANTGame.ResponseManager.SystemResponseManager.CallConnectResponse(false);
            }
        }
        catch (Exception ex)
        {
            IANTGame.ResponseManager.SystemResponseManager.CallConnectResponse(false);
            IANTGame.Service.DebugReturn(DebugLevel.ERROR, ex.Message);
            IANTGame.Service.DebugReturn(DebugLevel.ERROR, ex.StackTrace);
        }
    }
    // Use this for initialization
    void Start()
    {
        connection = new PhotonPeer(this, ConnectionProtocol.Udp);
        connection.Connect(ServerIP, AppName);

        StartCoroutine(DoService());
    }
Esempio n. 11
0
 // Use this for initialization
 void Start()
 {
     //利用PhotonPeer  与服务器端建立连接   选择通讯协议
     //通过被监听的对象  this  接收服务器端的响应
     peer = new PhotonPeer(this, ConnectionProtocol.Udp);
     peer.Connect("127.0.0.1:5055", "MyPhoton");
 }
Esempio n. 12
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();
            }
        }
Esempio n. 13
0
 void Awake()
 {
     instance = this;
     peer     = new PhotonPeer(this, protocol);
     peer.Connect(serverAddress, applicationName);
     //peer.Service();
 }
Esempio n. 14
0
 private void Awake()
 {
     address = "127.0.0.1:5055";
     Server  = "MyGameServer";
     peer    = new PhotonPeer(this, ConnectionProtocol.Udp);
     peer.Connect(address, Server);
 }
Esempio n. 15
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);
        }
Esempio n. 16
0
        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();
        }
Esempio n. 17
0
 void Start()
 {
     address = "127.0.0.1:5057";
     Server  = "LoginServer";
     peer    = new PhotonPeer(this, ConnectionProtocol.Udp);
     peer.Connect(address, Server);
 }
Esempio n. 18
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);
            }
        }
Esempio n. 19
0
 private void Connect()
 {
     if (PhotonPeer != null)
     {
         PhotonPeer.Connect(CONNECTION_STRING, APP_NAME);
     }
 }
Esempio n. 20
0
    public void Reconnect(string ip, string port, string app)
    {
        peer.Disconnect();
        string ipAndPort = ip + ":" + port;

        Debug.Log("重连服务器:" + ipAndPort + ",应用名:" + app);
        peer.Connect(ipAndPort, app);
    }
Esempio n. 21
0
    // Use this for initialization
    void Start()
    {
        // connect to Photon Server
        peer = new PhotonPeer(this, ConnectionProtocol.Udp);
        peer.Connect ("10.0.2.15:5055", "PhotonAckServer");

        StartCoroutine (doService ());
    }
Esempio n. 22
0
    public Chat()
    {
        peer = new PhotonPeer(this, ConnectionProtocol.Tcp);

        ChatGUI.MessagesTab1.Add("Connecting to chat server...");

        peer.Connect("191.238.97.27:4530", "ChatServer");
    }
Esempio n. 23
0
        private BaseListener ConnectPeer(BaseListener listener, ServerInfo server)
        {
            var peer = new PhotonPeer(listener, ConnectionProtocol.Udp);

            peer.Connect(string.Format("{0}:{1}", server.ip, server.port), server.appName);
            listener.SetPeer(peer);
            return(listener);
        }
Esempio n. 24
0
    public void Connect()
    {
        bool con = peer.Connect("127.0.0.1:5055", "PhotonIntro");

        Debug.Log("PeerID:" + peer.PeerID);
        Debug.Log("Peer state:" + peer.PeerState);
        Run();
    }
Esempio n. 25
0
    public void Start()
    {
        // connect to Photon server
        peer = new PhotonPeer(this, ConnectionProtocol.Udp);
        peer.Connect("127.0.0.1:5055", "PhotonAckServer");

        StartCoroutine(doService());
    }
Esempio n. 26
0
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("111------开始连接----");

        peer = new PhotonPeer(this, ConnectionProtocol.Udp);
        peer.Connect("127.0.0.1:5055", "MyGame1");
        connected = false;
    }
Esempio n. 27
0
        /// <summary>
        /// 类型:方法
        /// 名称:Connect
        /// 作者:taixihuase
        /// 作用:尝试通过 ip 地址、端口、传输协议及服务端进程名,与服务端连线
        /// 编写日期:2015/7/17
        /// </summary>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        /// <param name="connectionProtocol"></param>
        /// <param name="serverName"></param>
        public void Connect(string ip, int port, ExitGames.Client.Photon.ConnectionProtocol connectionProtocol,
                            string serverName)
        {
            string serverAddress = ip + ":" + port.ToString();

            Peer = new PhotonPeer(this, connectionProtocol);
            Peer.Connect(serverAddress, serverName);
        }
Esempio n. 28
0
 private void ServerSetup()
 {
     //服务器初始化
     //通过Listender接收服务器端的响应(监听服务器的类就是this)  链接方式(Udp)
     peer = new PhotonPeer(this, ConnectionProtocol.Udp);
     //设置链接的服务器IP和端口  要连接的服务器名
     peer.Connect("127.0.0.1:5055", "OA");
 }
Esempio n. 29
0
    public void Initialise()
    {
        _peer = new PhotonPeer(this, ConnectionProtocol.Udp);

        _peer.Connect(ServerAddress, ApplicationName);

        _state = new WaitingForConnection();
    }
Esempio n. 30
0
 protected override void Awake()
 {
     base.Awake();
     peer = new PhotonPeer(this, protocol);
     peer.Connect(serverAddress, applicationName);
     //切换场景不销毁该物体
     DontDestroyOnLoad(gameObject);
 }
Esempio n. 31
0
 // Update is called once per frame
 void Update()
 {
     if (!isConnect)
     {
         peer.Connect(serverAddress, applicationName);
     }
     peer.Service();
 }
Esempio n. 32
0
 void Awake()
 {
     _instance = this;//该脚本是绑定在Unity游戏组件中,相当于unity实例化了该对象
     peer      = new PhotonPeer(this, protocol);
     peer.Connect(serverAddress, applicationName);
     role = new Role();
     DontDestroyOnLoad(this);
 }
Esempio n. 33
0
    void Start()
    {
        Debug.Log("Connecting...");
        Connection = new PhotonPeer(this, ConnectionProtocol.Udp);
        Connection.Connect(ServerIP, AppName);

        StartCoroutine(doService());
    }
Esempio n. 34
0
 private void Update()
 {
     if (!connected)
     {
         peer.Connect(serverAddress, applicationName);           //连接服务器
     }
     peer.Service();                                             //获取服务,持续调用才能接受信息
 }
Esempio n. 35
0
    void Awake()
    {
        _instance = this;
        peer = new PhotonPeer(this,protocol);
        //peer连接服务器
        peer.Connect(serverAddress, applicationName);
        DontDestroyOnLoad(this.gameObject);

    }
Esempio n. 36
0
 public bool Connect()
 {
     peer = new PhotonPeer (this, ConnectionProtocol.Udp);
     if( peer.Connect("app.exitgamescloud.com:5055","912399f0-c8d8-4d11-bf0a-88924aa6ba31"))
     {
         return true;
     }
     return false;
 }
Esempio n. 37
0
    public void Start()
    {
        _photonPeer = new PhotonPeer(this, ConnectionProtocol.Udp);
        if (!_photonPeer.Connect("127.0.0.1:5055", "RuneSlinger"))
            Debug.LogError("Could not connect to photon.");

        _message = "";
        _messages = new List<string> { };
    }
Esempio n. 38
0
    public void Connect()
    {
        connected = false;
        //peer = new PhotonPeer(this, ConnectionProtocol.Tcp);
        //peer.Connect("127.0.0.1:4530", "ChatServer");

        peer = new PhotonPeer(this, ConnectionProtocol.WebSocket);
        peer.Connect("46.52.15.26:9090", "ChatServer");
    }
Esempio n. 39
0
 void Awake()
 {
     //Dns.GetHostName();
     IPAddress ipAddr = Dns.GetHostEntry("1462z254b3.iok.la").AddressList[0];
     string ip = ipAddr.ToString();//"1462z254b3.iok.la";//ipAddr.ToString();
     Debug.Log(ip);
     _instance = this;
     peer = new PhotonPeer(this, protocol);
     peer.Connect(ip+serverAddress, applicationName);
     DontDestroyOnLoad(this.gameObject);
 }
Esempio n. 40
0
 public bool Connect(string ip, string appname)
 {
     peer = new PhotonPeer(this, ConnectionProtocol.Udp);
     //"localhost:5055" "CSServer"
     if (peer.Connect(ip, appname)) 
     {
         return true;
     }
 //peer.OpCustom( )
     return false;
 }
Esempio n. 41
0
    public bool Connect()
    {
        stopwatch.Start();

        peer = new PhotonPeer(this, ConnectionProtocol.Udp);
        //连接Photon Cloud
        if (peer.Connect("app.exitgamescloud.com:5055", "d2482745-4d35-474c-96ce-4f5362e385a6"))
        {
            return true;
        }
        ////连接Photon Server
        //if (peer.Connect("localhost:5055", "LRServer"))
        //{
        //    return true;
        //}
        return false;
    }
Esempio n. 42
0
 public void Connect(string ip, int port, string serverNmae)
 {
     try
     {
         string serverAddress = ip + ":" + port.ToString();
         peer = new PhotonPeer(this, ConnectionProtocol.Udp);
         if (!peer.Connect(serverAddress, serverNmae))
         {
             OnConnectResponse(false);
         }
     }
     catch (Exception ex)
     {
         OnConnectResponse(false);
         DebugReturn(DebugLevel.ERROR, ex.Message);
         DebugReturn(DebugLevel.ERROR, ex.StackTrace);
     }
 }
Esempio n. 43
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;
                }
            }
        }
    }
Esempio n. 44
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;
        }
Esempio n. 45
0
 void Start()
 {
     peer = new PhotonPeer(this, ConnectionProtocol.Tcp);
     peer.Connect(IP, "MmoServer");
 }
Esempio n. 46
0
 public void Initialize()
 {
     Peer = new PhotonPeer(this, false);
     Peer.Connect(ServerAddress, ApplicationName);
     State = new WaitingForConnection(this);
 }
Esempio n. 47
0
 public void Initialize()
 {
     Peer = new PhotonPeer(this, ConnectionProtocol.Udp);
     Peer.Connect(ServerAddress, ApplicationName);
     State = new WaitingForConnection(_instance);
 }
    // Use this for initialization
    void Start()
    {
        connection = new PhotonPeer(this, ConnectionProtocol.Udp);
        connection.Connect(ServerIP, AppName);

        StartCoroutine(DoService());
    }
Esempio n. 49
0
 /// <summary>
 /// 类型:方法
 /// 名称:Connect
 /// 作者:taixihuase
 /// 作用:尝试通过 ip 地址、端口、传输协议及服务端进程名,与服务端连线
 /// 编写日期:2015/7/17
 /// </summary>
 /// <param name="ip"></param>
 /// <param name="port"></param>
 /// <param name="connectionProtocol"></param>
 /// <param name="serverName"></param>
 public void Connect(string ip, int port, ExitGames.Client.Photon.ConnectionProtocol connectionProtocol,
     string serverName)
 {
     string serverAddress = ip + ":" + port.ToString();
     Peer = new PhotonPeer(this, connectionProtocol);
     Peer.Connect(serverAddress, serverName);
 }
Esempio n. 50
0
 public void Init(PhotonPeer peer, string serverAddress, string applicationName, Login login)
 {
     m_peer = peer;
     m_peer.Connect(serverAddress, applicationName);
     m_login = login;
 }
Esempio n. 51
0
 public void Initialize()
 {
     _Peer = new PhotonPeer(this, ConnectionProtocol.Udp);
     _Peer.Connect(ServerAddress, ApplicationName);
     _State = new WaitForConnection(this);
 }