Esempio n. 1
0
        public RakNetClient(string ip, ushort port, System.Action <RakPeerInterface, Packet> msgHandler)
        {
            _sServerIP             = ip;
            _nServerPort           = port;
            processMessageHandler  = msgHandler;
            _RequestReadThreadStop = false;
            _bConnectSuccess       = false;

            _socketDesc = new RakNet.SocketDescriptor();

            _ReadThread = new Thread(new ThreadStart(_RunRead));
            _ReadThread.IsBackground = true;

            _State = RakNetClientState.None;
        }
Esempio n. 2
0
        public void InitPeer()
        {
            if (_peer != null)
            {
                return;
            }
            try
            {
                _peer = RakNet.RakPeerInterface.GetInstance();

                _State = RakNetClientState.PeerInitOK;
            }
            catch
            {
                _State = RakNetClientState.PeerInitError;
            }
        }
Esempio n. 3
0
        public void Start()
        {
            InitPeer();

            if (_State == RakNetClientState.PeerInitOK)
            {
                StartupResult result = _peer.Startup(1, _socketDesc, 1);
                Log.Debug("Start Result: " + result);
                if (result == StartupResult.RAKNET_STARTED)
                {
                    _State = RakNetClientState.StartUpOK;

                    RakNet.FT_ConnectProcess process = new RakNet.FT_ConnectProcess();
                    process.SetResultHandler(new RakNetClientResultHandler(this));
                    AttachInterface2(process);

                    ConnectionAttemptResult connectResult = _peer.Connect(_sServerIP, _nServerPort, "", 0);
                    Log.Debug("Connect Result: " + connectResult);
                    if (ConnectionAttemptResult.CONNECTION_ATTEMPT_STARTED == connectResult)
                    {
                        _State = RakNetClientState.ConnectOK;

                        _systemAddress = new SystemAddress(_sServerIP, _nServerPort);

                        _ReadThread.Start();
                    }
                    else
                    {
                        _State = RakNetClientState.ConnectError;
                    }
                }
                else
                {
                    Log.Debug("RakNet.RakPeerInterface.GetInstance() Error : " + result);
                    _State = RakNetClientState.StartUpError;
                }
            }
        }