Start() private method

Starts the new thread that will call the client to start.
private Start ( ) : void
return void
Esempio n. 1
0
        private void InitializeNetworkClient(IPAddress address)
        {
            NetworkClient.Start(address, (success, connectionFailure,
                                          authenticationFailure, timeout, connectionLost) => {
                if (!success)
                {
                    _displayText.text = "Error: networking failed";
                    Debug.Log($"Networking failed: SocketError:{connectionFailure} | " +
                              $"Auth:{authenticationFailure} | Timeout:{timeout} | ConnLost:{connectionLost}");
                    if (NetworkServer.Initialized)
                    {
                        NetworkServer.Stop();
                    }
                    return;
                }

                _displayText.text = "Loading world...";
                byte[] structure  = SerializeStructure().Array;

                // ReSharper disable once ConvertToLocalFunction
                UnityAction <Scene, LoadSceneMode> action = null;
                action = (scene, mode) => {
                    PlayingPlayerInitializer.OnNetworkingInitialized(structure);
                    SceneManager.sceneLoaded -= action;
                };

                SceneManager.sceneLoaded += action;
                SceneManager.LoadScene("Playing");
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Creates the network client, using current client configuration values
        /// </summary>
        private void SetupNetworking()
        {
            if (_netClient == null)
            {
                var receiveHandler = new MessagesReceiveHandler(_logger, NetMessages.ServerToClientMessages, _net_cl_log_messages.Boolean);

                RegisterMessageHandlers(receiveHandler);

                _netClient = new NetworkClient(
                    _logger,
                    this,
                    this,
                    new SendMappings(NetMessages.ClientToServerMessages),
                    receiveHandler,
                    _binaryDataDescriptorSet,
                    _objectListTypeRegistry,
                    _cl_name,
                    NetConstants.AppIdentifier,
                    _clientport.Integer,
                    _cl_resend.Float,
                    _cl_timeout.Float);

                _netClient.Start();
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            NetworkClient client = new NetworkClient("127.0.0.1", 7447);

            client.OnConnect = user =>
            {
                Random random = new Random();
                while (true)
                {
                    Console.ReadLine();
                    user.SendMessage(RamdomString());
                    //string str = Console.ReadLine();
                    //switch (str)
                    //{
                    //    case "close":
                    //        user.Disconnect();
                    //        break;
                    //    default:
                    //        user.SendMessage(str);
                    //        break;
                    //}
                }
            };

            client.OnCallBack = (user, packet) =>
            {
                Console.WriteLine(Encoding.UTF8.GetString(packet));
            };

            //client.Handle = new EasyHandle();
            client.Start();

            Thread.Sleep(-1);
        }
Esempio n. 4
0
        private static void Main(String[] args)
        {
            NetworkClient client = new NetworkClient();

            client.Start();
            //client.Connect();
            client.DiscoverPeers();

            NetClient netClient = client.NetClient;
            var       algo      = new NetXtea(netClient, NetworkSetting.Encryptionkey);

            while (!Console.KeyAvailable || Console.ReadKey().Key != ConsoleKey.Escape)
            {
                NetIncomingMessage msg;
                while ((msg = netClient.ReadMessage()) != null)
                {
                    msg.Decrypt(algo);

                    switch (msg.MessageType)
                    {
                    case NetIncomingMessageType.DiscoveryResponse:
                        Console.WriteLine("Found server at " + msg.SenderEndPoint + " name: " + msg.ReadString());
                        client.Connect(msg.SenderEndPoint);
                        break;

                    case NetIncomingMessageType.VerboseDebugMessage:
                    case NetIncomingMessageType.DebugMessage:
                    case NetIncomingMessageType.WarningMessage:
                    case NetIncomingMessageType.ErrorMessage:
                        Console.WriteLine(msg.ReadString());
                        break;

                    case NetIncomingMessageType.StatusChanged:
                        NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte();
                        if (status == NetConnectionStatus.Connected)
                        {
                            Console.WriteLine(" connected to" + msg.SenderConnection.RemoteUniqueIdentifier);
                        }
                        break;

                    case NetIncomingMessageType.Data:
                        var data    = msg.Data;
                        var message = SerializeTools.Deserialize <GameMessage>(data);
                        Console.WriteLine(message.ClientId + "-" + message.Content + "-" + (Int32)message.MsgCode);
                        client.SendMessage(client.CreateGameMessage <HelloMessage>());
                        break;
                    }
                    netClient.Recycle(msg);
                }
            }

            client.Shutdown();
        }
Esempio n. 5
0
        public ClientManager(Action <NetPeerConfiguration> configuration)
        {
            client = new NetworkClient("Chat",
                                       container =>
                                       container.RegisterPackages(Assembly.Load("Ginet.Chat.Packages")),
                                       configuration);

            client.Start(NetDeliveryMethod.UnreliableSequenced, 0);
            client.ProcessMessagesInBackground();

            DefaultPackageSender = client.LiftSender((msg, peer) =>
                                                     peer.SendMessage(msg, NetDeliveryMethod.ReliableOrdered));
        }
Esempio n. 6
0
 private void OnClientConnected_Click(object sender, EventArgs e)
 {
     if (!NetworkClient.Connected)
     {
         NetworkClient.RegisterHandler(InternalMessages.CONNECTED, OnConnectedToServer);
         NetworkClient.RegisterHandler(InternalMessages.DISCONNECT, OnDisconectedFromServer);
         NetworkClient.RegisterHandler(100, OnClientChatRecived);
         NetworkClient.Start(1985);
     }
     else
     {
         button1.Text      = "Connect";
         richTextBox1.Text = "";
         richTextBox1.AppendText("Disconected from Server!\n");
         NetworkClient.Stop();
     }
 }
Esempio n. 7
0
 private void OnClientOnlyConnected(bool success, SocketError connectionFailure,
                                    byte authenticationFailure, bool timeout, bool connectionLost)
 {
     if (success)
     {
         Debug.Log("Networking initialization complete as: Client-Only");
         OnSuccess();
     }
     else
     {
         Debug.Log($"Client-only initialization failed; SocketError:{connectionFailure}" +
                   $" | Auth:{authenticationFailure} | Timeout:{timeout} | ConnLost:{connectionLost}");
         NetworkServer.Start();
         NetworkServer.ConnectHandler = client => { };
         NetworkClient.Start(IPAddress.Loopback, OnHostConnected);
     }
 }
Esempio n. 8
0
        private void Connect(DbEntry entry, int x)
        {
            // if (connecting) return;

            NetworkClient.Stop();
            connecting = true;
            if (connected != null)
            {
                index = -1;
                connected.connected = false;
                DatabaseManager.Instance.AddOrUpdateEntry(connected);
                Draw();
            }
            index        = x;
            connected    = entry;
            jLabel1.Text = "Connecting ...";
            RegisterHandlers();
            NetworkClient.Start(entry.Ip, entry.port);
        }
Esempio n. 9
0
 private void Start()
 {
     Debug.Log("Initializating networking...");
     NetworkClient.Start(IPAddress.Loopback, OnClientOnlyConnected);
     Destroy(gameObject);
 }
Esempio n. 10
0
        public void Connect()
        {
            if (_hasConnected == true)
            {
                return;
            }
            _hasConnected = true;
            if (!string.IsNullOrWhiteSpace(Host) && Port != 0)
            {
                //Do a deferred web request to get a token
                Logger.Trace("Doing web request for auth token");
                Task.Run(async() =>
                {
                    Status       = ClientStatus.Authenticating;
                    Message      = "Authenticating with ZSB servers...";
                    string token = "OFFLINE";
                    try
                    {
                        if (!GlobalSettings.Instance.NoLoginMode)
                        {
                            token = await ZSB.DrmClient.Multiplayer.GetServerTokenAsync();
                        }
                    }
                    //Catch issues that force us offline
                    catch (UnableToAccessAccountServerException)
                    { } //Offline mode
                    catch (AccountServerException)
                    { if (GlobalSettings.Trace)
                      {
                          throw;
                      }
                    }
                    catch (InvalidAccountServerResponseException)
                    { if (GlobalSettings.Trace)
                      {
                          throw;
                      }
                    }
                    //Get the username and UID
                    _playerName = GlobalSettings.Instance.NoLoginMode ? GenerateOfflineUsername() : ZSB.DrmClient.User.Username;
                    _playerId   = GlobalSettings.Instance.NoLoginMode ? Guid.NewGuid() : ZSB.DrmClient.User.UniqueId;

                    //And send connection message

                    Status = ClientStatus.Connecting;

                    Logger.Info($"Connecting to {Host}:{Port} (DRM Status: (" + (ZSB.DrmClient.Offline ? "Offline" : "Online") + ")");
                    Logger.Info($"Client version {StaticSettings.VersionMajor}.{StaticSettings.VersionMinor}");
                    Logger.Info($"Name: {_playerName}.");

                    Message = $"Connecting to {Host}:{Port} in " + (ZSB.DrmClient.Offline ? "Offline" : "Online") + " mode...";

                    var msg = NetworkClient.CreateMessage();
                    msg.Write(_playerId.ToByteArray());
                    msg.Write(_playerName);
                    msg.Write(token);
                    msg.Write(Password ?? ""); //Write an empty password just in case
                    msg.Write(StaticSettings.VersionMajor);
                    msg.Write(StaticSettings.VersionMinor);
                    NetworkClient.Start();
                    NetworkClient.Connect(Host, Port, msg);
                    Logger.Trace("Connection message sent");
                });
            }
        }
Esempio n. 11
0
 private void InitNetworkClient()
 {
     loginDelegate = new LoginServerDelegate(this);
     loginClient   = new NetworkClient();
     loginClient.Start();
 }