Beispiel #1
0
 // Create a client and connect to the server port
 public void SetupClient()
 {
     myClient = new NetworkClient();
     myClient.RegisterHandler(MsgType.Connect, OnConnected);
     myClient.RegisterHandler(MyMsgType.Info, OnInfo);
     myClient.Connect("10.250.235.162", 3000);
 }
 public void connect(string server, NetworkMessageDelegate onConnect)
 {
     client = new NetworkClient ();
     if(onConnect != null)
         client.RegisterHandler (MsgType.Connect, onConnect);
     client.Connect (server, PORT);
 }
Beispiel #3
0
        public override void InitializeScene(ICanvas canvas)
        {
            // Connect with simulator
            connection = new NetworkClient();
            if (!connection.Connect("ganberg2", 9999))
            {
                throw new ApplicationException("Unable to establish connection with host.");
            }
            else
            {
                connection.Subscribe("TimeTick");
                connection.Subscribe("ViewProUpdate");
            }

            // Create and initialize Gameboard.
            background = new Obj_Sprite(texture_file, SpriteFlags.SortTexture | SpriteFlags.AlphaBlend);
            background.Initialize(canvas);
            background.Position = new Vector3(0, 0, 0);
            background.Rotation = new Vector3(0, 0, 0);
            background.Scaling = new Vector3(1, 1, 1);
            background.Texture(canvas);

            // Initialize and create Font;
            this._myFont = canvas.CreateFont(new System.Drawing.Font("Arial", 10));
            message = string.Empty;

            //f16 = new Obj_Sprite("f16.png", SpriteFlags.AlphaBlend);
            //f16.Initialize(canvas);
            //f16.Texture(canvas);
            //f16.Position = new Vector3(0, 0, 0);
            //f16.Rotation = new Vector3(0, 0, 0);
            //f16.Scaling = new Vector3(1, 1, 1);

        }
 public void SetupClient()
 {
     myClient = new NetworkClient();
     myClient.RegisterHandler(MsgType.Connect, OnConnected);
     myClient.Connect("192.16.7.21", 8888);
     isAtStartup = false;
 }
Beispiel #5
0
 private void SetupClient()
 {
     if (client == null)
     {
         client = new NetworkClient();
         client.Connect("127.0.0.1", serverPort);
     }
 }
Beispiel #6
0
 void Awake()
 {
     myClient = new NetworkClient ();
     ConnectionConfig config = new ConnectionConfig ();
     config.AddChannel (QosType.ReliableFragmented);
     myClient.Configure (config, 1);
     myClient.Connect (IP, 7777);
     myClient.RegisterHandler (MyMsgType.Info, OnInfoMessage);
 }
    void setupClient()
    {
        //registerPrefabs ();
        //Spawn ();

        myClient = new NetworkClient();
        myClient.RegisterHandler(MsgType.Connect, OnConnectedRemotePlayer);
        myClient.RegisterHandler (MsgType.Error, OnErrorRemotePlayer);
        myClient.Connect(gameIP, gamePort);
    }
Beispiel #8
0
    public void Start()
    {
        ClientScene.RegisterPrefab(Player);
        ClientScene.RegisterPrefab (Bolt);

        myClient = new NetworkClient();
        Debug.Log("oollolo");
        //myClient.RegisterHandler(MsgType.Connect, OnConnected);
        myClient.Connect("127.0.0.1", 7777);
    }
    public void SetupClient()
    {
        StartClient();
        Debug.Log("SetupClient()");

        discovery.Initialize();
        discovery.StartAsClient();

        myClient = new NetworkClient();
        myClient.Connect("127.0.0.1", 4444);
    }
	// Use this for initialization
	void Start () {
		nc = new NetworkClient ();
		nc.Connect("192.168.1.19", 5678);
		Debug.Log ("Client : " + nc);
		Debug.Log (nc.isConnected);
		if (nc.isConnected) {
			int score = snake.score;
			Debug.Log ("Derp " + score);
			scoreText.text = "Score: " + score;
		} else {
			scoreText.text = "Score: ERROR";
		}
	}
    // Create a client and connect to the server port
    public void SetupClient()
    {
        Debug.Log ("SetupClient.");
        foreach (GameObject prefab in prefabs) {
            if (prefab != null)
                ClientScene.RegisterPrefab (prefab);
        }

        myClient = new NetworkClient ();

        myClient.RegisterHandler (MsgType.Connect, OnConnected);
        myClient.Connect (base.networkAddress, base.networkPort);
    }
    void Start()
    {
        //on client, this isn't required but is nice for testing.
        Application.runInBackground = true;

        var globals = FindObjectOfType<GlobalAssets>();

        _networkStateEntityProtoType = globals.NetworkEntityStatePrototype.GetComponent<NetworkIdentity>();

        ClientScene.RegisterSpawnHandler(_networkStateEntityProtoType.assetId, OnSpawnEntity, OnDespawnEntity);

        _client = new NetworkClient();
        _client.Connect("localhost", 7777);
        _client.RegisterHandler(MsgType.Connect, OnClientConnected);

    }
Beispiel #13
0
	public void joinGame()
	{
		// Check if there is a room

		// Has the game Started?

		// If no, send the player to the Waiting For Players page

		// If yes, give error message.
		Debug.Log (string.Format ("join button clicked"));
		client = new NetworkClient();
		client.Connect ("192.168.1.103", 4444);
		client.RegisterHandler(MsgType.Connect, OnConnected);
		client.RegisterHandler(MsgType.Error, OnError);
		client.RegisterHandler (Message.GET_HAS_ROOM, OnGetRoom);
	}
Beispiel #14
0
        static void Main(string[] args)
        {
            string scenarioFile = args[0];
            new ScenarioToQueues(scenarioFile);
 //           string hostname = "dgeller";
            string hostname=args[1];
//            int port = 9999;
            int port = int.Parse(args[2]);
 //           string simModelName = "SimulationModel.xml";
            string simModelName = args[3];
            NetworkClient c = new NetworkClient();
            c.Connect(hostname, port);
            EventCommunicator eventCommunicator = new EventCommunicator(c);

            SimulationModelReader smr = new SimulationModelReader();
            SimulationModelInfo simModelInfo = smr.readModel(simModelName);

            SimulationEventDistributor dist = new SimulationEventDistributor(ref simModelInfo);
            SimulationEventDistributorClient cc = new SimulationEventDistributorClient();

            dist.RegisterClient(ref cc);



            sink = new Watcher(400);
            ThreadStart stub = new ThreadStart(sink.WatcherThread);
            Thread stubThread = new Thread(stub);
            stubThread.Start();


            for (int i = 0; i < 5; i++) // in test the move happens at time 2
            {
                TimerTicker.NextTick();
            }
            IncomingList.Add(new MoveComplete_Event("UNIT0"));
            for (int i = 0; i < 2; i++)
            {
                TimerTicker.NextTick();
            }
 
            Console.WriteLine("The end");


        }
Beispiel #15
0
 public void OnMatchJoined(JoinMatchResponse matchJoin)
 {
     if (matchJoin.success)
     {
         Debug.Log("Join match succeeded");
         if (matchCreated)
         {
             Debug.LogWarning("Match already set up, aborting...");
             return;
         }
         Utility.SetAccessTokenForNetwork(matchJoin.networkId, new NetworkAccessToken(matchJoin.accessTokenString));
         NetworkClient myClient = new NetworkClient();
         myClient.RegisterHandler(MsgType.Connect, OnConnected);
         myClient.Connect(new MatchInfo(matchJoin));
     }
     else
     {
         Debug.LogError("Join match failed");
     }
 }
Beispiel #16
0
    void Start()
    {
        manager = GetComponent<NetworkManager>();
        manager.StartMatchMaker();
        matcher = manager.matchMaker;

        matcher.ListMatches(0, ListSize, "", (matches) => {
            if (matches.success) {
                if (matches.matches.Count > 0 && !OnlyHost) {
                    matcher.JoinMatch(matches.matches[0].networkId, "", (join) => {
                        if (join.success) {
                            Utility.SetAccessTokenForNetwork(join.networkId, new NetworkAccessToken(join.accessTokenString));
                            NetworkClient client = new NetworkClient();
                            client.RegisterHandler(MsgType.Connect, (connected) => {
                                Debug.Log("Connected");
                            });
                            client.Connect(new MatchInfo(join));
                            manager.StartClient();
                        } else {
                            Debug.LogError("Could not join match");
                        }
                    });
                } else {
                    matcher.CreateMatch(URandom.value.ToString(), PlayerCountPerRoom, Advertise, "", (created) => {
                        if (created.success) {
                            Debug.Log("Create match succeeded");
                            Utility.SetAccessTokenForNetwork(created.networkId, new NetworkAccessToken(created.accessTokenString));
                            NetworkServer.Listen(new MatchInfo(created), 9000);
                            manager.StartHost();
                            isHost = true;
                        } else {
                            Debug.LogError("Could not create match");
                        }
                    });
                }
            } else {
                Debug.LogError("Could not recieve list of matchces");
            }
        });
    }
Beispiel #17
0
    public void InitializeClient()
    {
        if (client != null)
        {
            Debug.LogError("Already connected");
            return;
        }

        client = new NetworkClient();
        client.Connect(MasterServerIpAddress, MasterServerPort);

        // system msgs
        client.RegisterHandler(MsgType.Connect, OnClientConnect);
        client.RegisterHandler(MsgType.Disconnect, OnClientDisconnect);
        client.RegisterHandler(MsgType.Error, OnClientError);

        // application msgs
        client.RegisterHandler(MasterMsgTypes.RegisteredHostId, OnRegisteredHost);
        client.RegisterHandler(MasterMsgTypes.UnregisteredHostId, OnUnregisteredHost);
        client.RegisterHandler(MasterMsgTypes.ListOfHostsId, OnListOfHosts);

        //DontDestroyOnLoad(gameObject);
    }
        public void OnStartServerInHostModeSetsIsClientTrue()
        {
            CreateNetworked(out GameObject _, out NetworkIdentity identity);

            // call client connect so that internals are set up
            // (it won't actually successfully connect)
            NetworkClient.Connect("localhost");

            // manually invoke transport.OnConnected so that NetworkClient.active is set to true
            Transport.activeTransport.OnClientConnected.Invoke();
            Assert.That(NetworkClient.active, Is.True);

            // isClient needs to be true in OnStartServer if in host mode.
            // this is a test for a bug that we fixed, where isClient was false
            // in OnStartServer if in host mode because in host mode, we only
            // connect the client after starting the server, hence isClient would
            // be false in OnStartServer until way later.
            // -> we have the workaround in OnStartServer, so let's also test to
            //    make sure that nobody ever breaks it again
            Assert.That(identity.isClient, Is.False);
            identity.OnStartServer();
            Assert.That(identity.isClient, Is.True);
        }
Beispiel #19
0
    public void Join()
    {
        client = new NetworkClient();

        client.RegisterHandler(MsgType.Connect, OnConnected);
        client.RegisterHandler(MsgType.Disconnect, OnDisconnected);

        // custom msgs
        client.RegisterHandler(CustomNetMsg.Ready, GotReady);
        client.RegisterHandler(CustomNetMsg.Name, GotName);
        client.RegisterHandler(CustomNetMsg.Role, GotRole);
        client.RegisterHandler(CustomNetMsg.Id, GotId);
        client.RegisterHandler(CustomNetMsg.PlayerDisconnected, GotPlayerDisconnected);
        client.RegisterHandler(CustomNetMsg.Player, GotPlayer);
        client.RegisterHandler(CustomNetMsg.StartGame, GotStartGame);
        client.RegisterHandler(CustomNetMsg.Spawn, GotSpawnLocation);
        client.RegisterHandler(CustomNetMsg.Move, GotMove);
        client.RegisterHandler(CustomNetMsg.DissonanceId, GotDissonanceId);
        client.RegisterHandler(CustomNetMsg.Tile, GotTile);
        client.RegisterHandler(CustomNetMsg.Attack, GotAttack);

        client.Connect(ip, 45555);
    }
Beispiel #20
0
    public void Connect()
    {
        loadingText.text = Language.GetText(8);
        panel_Loading.Open();

        nc = new NetworkClient();
        nc.Connect(string.IsNullOrEmpty(debugIp.text) ? settings.targetIp : debugIp.text, settings.port);

        nc.RegisterHandler(MsgType.Connect, OnConnected);
        nc.RegisterHandler(MsgType.Disconnect, OnDisconnect);
        nc.RegisterHandler(MTypes.SessionUpdate, OnSessionUpdate);
        nc.RegisterHandler(MTypes.AgentInfo, OnAgentInfo);
        nc.RegisterHandler(MTypes.SyncPosition, OnSyncPosition);
        nc.RegisterHandler(MTypes.AgentMove, OnAgentMove);
        nc.RegisterHandler(MTypes.AgentStop, OnAgentStop);
        nc.RegisterHandler(MTypes.AgentDestroy, OnAgentDestroy);
        nc.RegisterHandler(MTypes.StartSkill, OnStartSkill);
        nc.RegisterHandler(MTypes.EndSkill, OnEndSkill);
        nc.RegisterHandler(MTypes.AgentHealth, OnAgentHealth);
        nc.RegisterHandler(MTypes.SkillDestroy, OnSkillDestroy);
        nc.RegisterHandler(MTypes.SkillSpawn, OnSkillSpawn);
        nc.RegisterHandler(MTypes.AgentAim, OnAgentAim);
        nc.RegisterHandler(MTypes.SkillEffect, OnSkillEffect);
        nc.RegisterHandler(MTypes.HeroInfo, OnHeroInfo);
        nc.RegisterHandler(MTypes.Cooldown, OnCooldown);
        nc.RegisterHandler(MTypes.KillInfo, OnKillInfo);
        nc.RegisterHandler(MTypes.ScoreInfo, OnScoreInfo);
        nc.RegisterHandler(MTypes.SessionEnd, OnSessionEnd);
        nc.RegisterHandler(MTypes.RoundComplete, OnRoundComplete);
        nc.RegisterHandler(MTypes.SkillInfo, OnSkillInfo);
        nc.RegisterHandler(MTypes.AgentLevel, OnAgentLevel);
        nc.RegisterHandler(MTypes.LevelInfo, OnLevelInfo);
        nc.RegisterHandler(MTypes.MapInfo, OnMapInfo);
        nc.RegisterHandler(MTypes.AgentBuff, OnAgentBuff);
        nc.RegisterHandler(MTypes.Teleport, OnTeleport);
        nc.RegisterHandler(MTypes.Hook, OnHook);
    }
Beispiel #21
0
        public IEnumerator _ConnectionId()
        {
            using (NetworkServer server = new NetworkServer())
            {
                server.Start(localPort);

                using (NetworkClient client = new NetworkClient())
                {
                    client.Connect(localAddress, localPort);

                    foreach (var o in Wait())
                    {
                        yield return(null);
                    }

                    Assert.AreEqual(server.Connections.Count(), 1);
                    int connectionId = server.Connections.First().ConnectionId;
                    Assert.IsTrue(connectionId > 0, connectionId.ToString());
                    Assert.IsTrue(client.Connection.IsConnected);
                    Assert.AreEqual(client.Connection.ConnectionId, connectionId);
                    Assert.AreEqual(client.Connection, server.Connections.First());
                }
            }
        }
    public void SetupNetwork()
    {
        netManagerObj  = new GameObject();
        networkManager = netManagerObj.AddComponent <NetworkManager>();
        networkManager.playerPrefab = Resources.Load("PlayerGameObject", typeof(GameObject)) as GameObject;

        Assert.IsNotNull(networkManager.playerPrefab);

        networkManager.customConfig     = true;
        networkManager.networkAddress   = _ip;
        networkManager.networkPort      = _port;
        networkManager.autoCreatePlayer = false;

        networkMigrManager = netManagerObj.AddComponent <NetworkMigrationManager>();
        Assert.IsTrue(networkManager.StartServer(), "Server was not started!");
        networkManager.SetupMigrationManager(networkMigrManager);

        client = networkManager.StartClient();
        client.Connect(_ip, _port);
        Assert.IsNull(client.connection, "Client is not connected");

        networkMigrManager.Initialize(client, networkManager.matchInfo);
        networkMigrManager.SendPeerInfo();
    }
    public void SetupClient(string ip)
    {
        string conIP;

        if (ip == "")
        {
            if (ipAdress.text != "")
            {
                conIP = ipAdress.text;
            }
            else
            {
                conIP = "127.0.0.1";
            }
        }
        else
        {
            conIP = ip;
        }
        myClient = new NetworkClient();
        myClient.RegisterHandler(MsgType.Connect, OnConnected);
        myClient.Connect(conIP, 7777);
        isAtStartup = false;
    }
    //check that Server/Client can be started
    public IEnumerator NetworkServerClientCanBeStartedWithConfig()
    {
        string netAddress = "127.0.0.1";
        int    netPort    = 8887;

        netManager.networkAddress = netAddress;
        netManager.networkPort    = netPort;

        netManager.StartServer();

        NetworkClient netClient = netManager.StartClient();

        netClient.Connect(netAddress, netPort);

        if (!netClient.isConnected)
        {
            yield return(null);
        }

        Assert.IsTrue(netClient.isConnected,
                      "Client did not connect to server");

        netManager.StopServer();
    }
Beispiel #25
0
    public void InitializeClient()
    {
        if (client != null)
        {
            Debug.LogError("Already connected");
            return;
        }

        client = new NetworkClient();

        RegisterHandlers();

        //Parse address
        Uri url;
        int port = GameServer.port;

        if (Uri.TryCreate("http://" + hostAddress, UriKind.Absolute, out url))
        {
            if (url.Port != 80)
            {
                port = url.Port;
            }
            Debug.Log("IP: " + url.Host + " Port: " + port);
        }
        else
        {
            Debug.LogError("Error parsing IP Address");
            client.Shutdown();
            client = null;
            return;
        }

        client.Connect(url.Host, port);

        DontDestroyOnLoad(this.gameObject);
    }
Beispiel #26
0
    public void Connect(string ip, int port)
    {
        ConnectionConfig cc = new ConnectionConfig();

        cc.AddChannel(QosType.Reliable);
        cc.AddChannel(QosType.ReliableFragmented);
        networkClient = new NetworkClient();
        networkClient.Configure(cc, 1);
        networkClient.RegisterHandler(MsgType.Connect, x =>
        {
            isConnected = true;
            if (OnConnected != null)
            {
                OnConnected();
            }
        });
        networkClient.RegisterHandler(MsgType.Disconnect, x =>
        {
            if (isConnected)
            {
                isConnected = false;
                if (OnDisconnected != null)
                {
                    OnDisconnected();
                }
            }
            else //connection failure
            {
                if (OnFailedToConnect != null)
                {
                    OnFailedToConnect();
                }
            }
        });
        networkClient.Connect(ip, port);
    }
Beispiel #27
0
        IEnumerator <CustomYieldInstruction> ConnectCoroutine(PTSession session)
        {
            if (!myClient.isConnected && session != null)
            {
                //
                ResetClient();

                //Check the player's name is valid (no duplica)
                //bool isClientNameValid = true;
                if (isClientNameValid())
                {
                    //Actuall connect happens here
                    myClient.Connect(session.ip, session.port);

                    //wait until the connection is established
                    yield return(new WaitUntil(() => myClient.isConnected));

                    //Send the connected event msg to server
                    PTMessage msg = new PTMessage();
                    msg.senderName = playerName;
                    myClient.Send((short)PTEvent.Connect, msg);
                }
            }
        }
Beispiel #28
0
    public void SetupClient(bool simulatedLatency)
    {
        ConnectionConfig config = new ConnectionConfig();

        //config.por
        //MyNetworkManager.singleton.StartServer();

        config.NetworkDropThreshold = 90;
        config.ReducedPingTimeout   = 1000;
        config.PingTimeout          = 1000;
        config.AddChannel(QosType.ReliableSequenced);
        config.AddChannel(QosType.AllCostDelivery);
        myClient = new NetworkClient();
        myClient.Configure(config, 10);
        myClient.RegisterHandler(MsgType.Connect, OnConnected);
        if (simulatedLatency)
        {
            myClient.ConnectWithSimulator(m_ipText.text, m_gameServerPort, 150, 0);
        }
        else
        {
            myClient.Connect(m_ipText.text, m_gameServerPort);
        }
    }
Beispiel #29
0
 public void StartClient()
 {
     if (networkClient == null)
     {
         Debug.Log("StartClient");
         networkClient = new NetworkClient();
         networkClient.Connect(ipv4, portTCP); // port server的端口,用于建立链接
         networkClient.RegisterHandler(MsgType.Connect, OnConnect);
         networkClient.RegisterHandler(MsgType.Disconnect, reconnectHandler.OnDisconnect);
         networkClient.RegisterHandler(CustomMsgType.RoleState, roleChooseHandler.OnReceiveRoleState);
         networkClient.RegisterHandler(CustomMsgType.ClientChange, panelChanger.ChangePanel);
         networkClient.RegisterHandler(CustomMsgType.GroupState, joystickHandler.OnClientReciveMessage);
         networkClient.RegisterHandler(CustomMsgType.AdvanceControl, advanceControlHandler.OnReceiveAdvanceControl);
         networkClient.RegisterHandler(CustomMsgType.Session, reconnectHandler.OnReceiveSession);
         networkClient.RegisterHandler(CustomMsgType.Stage, panelChanger.ChangeStage);
     }
     else
     {
         if (!networkClient.isConnected)
         {
             networkClient.Connect(ipv4, portTCP);
         }
     }
 }
Beispiel #30
0
        public void Send()
        {
            // register server handler
            int called = 0;

            NetworkServer.RegisterHandler <AddPlayerMessage>((conn, msg) => { ++called; }, false);

            // connect a regular connection. not host, because host would use
            // connId=0 but memorytransport uses connId=1
            NetworkClient.Connect("localhost");
            // update transport so connect event is processed
            ((MemoryTransport)Transport.activeTransport).LateUpdate();

            // send it
            AddPlayerMessage message = new AddPlayerMessage();

            NetworkClient.Send(message);

            // update transport so data event is processed
            ((MemoryTransport)Transport.activeTransport).LateUpdate();

            // received it on server?
            Assert.That(called, Is.EqualTo(1));
        }
	// Use this for initialization
	void Start () {
		nc = new NetworkClient ();
		nc.Connect("192.168.1.19", 5678);
		nc.RegisterHandler (Networking.CustomMsgType.SpreadMiniGameMessage, getInputFromServer );
	
	}
Beispiel #32
0
 //=====================================================
 //Кнопки
 //=====================================================
 //подключение по введеному в поле ip адресу и вывод сообщения на
 //экран с результатом подлкючения
 public void ConnectClick()
 {
     ip = InputServerIP.text;
     MessageLog.text = "Connecting to " + ip;
     client.Connect(ip, port);
 }
 private static async Task Connect()
 {
     client = new NetworkClient();
     await client.Connect(NetworkConstants.ServerUrl, NetworkConstants.MainHubName);
 }
Beispiel #34
0
 /// <summary>
 /// Connect client to a NetworkServer instance.
 /// </summary>
 /// <param name="address"></param>
 public void Connect(string address)
 {
     NetworkClient.Connect(address);
 }
Beispiel #35
0
 // Create a client and connect to the server port
 public void SetupClient2()
 {
     myClient2 = new NetworkClient();                 //Instantiate the client
     myClient2.Connect(SERVER_ADDRESS, SERVER_PORT2); //Attempt to connect, this will send a connect request which is good if the OnConnected fires
 }
Beispiel #36
0
 public void OnReceivedBroadcast(string fromAddress, string data)
 {
     foreach (GameObject but in joinGameButtons)
     {
         if (but.name == fromAddress)
         {
             return;
         }
     }
     GameObject newButton = GameObject.Instantiate(joinButtonPrefab);
     newButton.name = fromAddress;
     newButton.transform.parent = joinGameUI.transform;
     newButton.transform.localPosition = new Vector2(newButton.transform.position.x, joinListY);
     newButton.GetComponentInChildren<Text>().text = data;
     newButton.GetComponent<Button>().onClick.AddListener(() => {
         SceneManager.LoadScene("main");
         GameObject.Find("Global").GetComponent<Game>().Networked = true;
         NetworkClient myClient = new NetworkClient();
         myClient.Connect(fromAddress, net.LOCAL_PORT);
     });
     joinListY -= 50;
     joinGameButtons.Add(newButton);
 }
Beispiel #37
0
 public void ConnectToServer()
 {
     // Connect to the server
     client.Connect(inputIP.text, port);
 }
 public void SetupClient()
 {
     myClient = new NetworkClient();
     myClient.RegisterHandler(MsgType.Connect, OnConnected);
     myClient.Connect("192.168.1.83", 80);
 }
 void SetupClient()
 {
     ClientScene.RegisterPrefab (this.pointObject.gameObject);
     ClientScene.RegisterPrefab (this.baseObject.gameObject);
     mode = false;
     Debug.Log("Verbinde mit Server...");
     client = new NetworkClient ();
     client.RegisterHandler (MsgType.Connect, OnConnected);
     client.Connect (adress, System.Convert.ToInt16 (port));
     client.RegisterHandler (MyMsgType.IDComponentUpdateMessage, OnUpdateDistributionRequestMsg);
     ClientScene.AddPlayer (0);
 }
Beispiel #40
0
 public static void Connect(string serverIp, int serverPort)
 {
     _client.Connect(serverIp, serverPort);
 }
        /// <summary>
        /// Reconnects to a CityServer.
        /// </summary>
        public void Reconnect(ref NetworkClient Client, CityInfo SelectedCity, LoginArgsContainer LoginArgs)
        {
            Client.Disconnect();

            if (LoginArgs.Enc == null)
            {
                Debug.WriteLine("LoginArgs.Enc was null!");
                LoginArgs.Enc = new GonzoNet.Encryption.AESEncryptor(Convert.ToBase64String(PlayerAccount.Hash));
            }
            else if (LoginArgs.Username == null || LoginArgs.Password == null)
            {
                Debug.WriteLine("LoginArgs.Username or LoginArgs.Password was null!");
                LoginArgs.Username = PlayerAccount.Username;
                LoginArgs.Password = Convert.ToBase64String(PlayerAccount.Hash);
            }

            Client.Connect(LoginArgs);
        }
 /// <summary>
 /// Reconnects to a CityServer.
 /// </summary>
 public void Reconnect(ref NetworkClient Client, CityInfo SelectedCity, LoginArgsContainer LoginArgs)
 {
     Client.Disconnect();
     Client.Connect(LoginArgs);
 }
Beispiel #43
0
 public void StartConnect()
 {
     client = new NetworkClient();
     client.RegisterHandler(MyMsgType.Message, ReceiveMessage);
     client.Connect(serverIP, port);
 }
Beispiel #44
0
 public void OnSBMatchJoined(JoinMatchResponse matchJoin)
 {
     if (matchJoin.success)
     {
         Debug.Log("Join match succeeded");
         Utility.SetAccessTokenForNetwork(matchJoin.networkId, new NetworkAccessToken(matchJoin.accessTokenString));
         SceneManager.LoadScene("main");
         GameObject.Find("Global").GetComponent<Game>().Networked = true;
         NetworkClient myClient = new NetworkClient();
         //myClient.RegisterHandler(MsgType.Connect, OnConnected);
         myClient.Connect(new MatchInfo(matchJoin));
     }
     else
     {
         Debug.LogError("Join match failed");
     }
 }
Beispiel #45
0
        //[STAThread]
        static void Main(string[] args)
        {
            string hostname = args[0];
            int port = Int32.Parse(args[1]);
            string simModelName = args[2];

            SimulationModelReader smr = new SimulationModelReader();
            SimulationModelInfo simModelInfo = smr.readModel(simModelName);

            SimulationEventDistributor dist = new SimulationEventDistributor(ref simModelInfo);
            SimulationEventDistributorClient cc = new SimulationEventDistributorClient();

            dist.RegisterClient(ref cc);
            cc.Subscribe("ALL");

            ScenarioReader scenarioReader = new ScenarioReader();
            QueueManager queueManager = QueueManager.UniqueInstance();

            

            c = new NetworkClient();
            c.Connect(hostname, port);
            EventListener myEL = EventListener.UniqueInstance(c);
            int t = 0;
            int dt = simModelInfo.simulationExecutionModel.updateFrequency;

            SimulationEvent tick = SimulationEventFactory.BuildEvent(ref simModelInfo, "TimeTick");
            ((IntegerValue)tick["Time"]).value = t;

            ConsoleKeyInfo cki;
            //Console.TreatControlCAsInput = false;  //This explodes my code for some reason, but is in Gabe's client code and works fine, what does it do?
            Console.CancelKeyPress += new ConsoleCancelEventHandler(MyExitHandler);

            List<SimulationEvent> events = null;

            while (c.IsConnected() && queueManager.count() > 0)
            {

                //Read incoming events queue
                //if any events deal with a conditional event, remove the conditional
                //event from the conditional list, and place it onto the event queue
                //if a unit dies, remove them from the event queue and condition list

                while (c.IsConnected() && !(queueManager.eventsAtTime(t)))
                {
                    events = c.GetEvents();
                    foreach (SimulationEvent e in events)
                    {
                        if (e.eventType == "MoveDone")
                            c.PutEvent(myEL.MoveDoneReceived(e, simModelInfo, tick));

                        System.Console.WriteLine(SimulationEventFactory.XMLSerialize(e));
                    }



                    ((IntegerValue)tick["Time"]).value = t;
                    c.PutEvent(tick);
                    //Console.WriteLine("Sending...");
                    //Console.WriteLine(SimulationEventFactory.XMLSerialize(tick));
                    Thread.Sleep(dt);

                    t += dt;
                }

                if (c.IsConnected())
                {
                    QueueManager.sendEventsAtTime(t, c);
                    ((IntegerValue)tick["Time"]).value = t;
                    c.PutEvent(tick);
                    //Console.WriteLine("Sending...");
                    //Console.WriteLine(SimulationEventFactory.XMLSerialize(e));
                    t += dt;
                }
                


            }

            while (c.IsConnected())
            {
                ((IntegerValue)tick["Time"]).value = t;
                c.PutEvent(tick);
                //Console.WriteLine("Sending...");
                //Console.WriteLine(SimulationEventFactory.XMLSerialize(tick));
                Thread.Sleep(dt);

                t += dt;
            }
        }
 public void Connect(NetworkClient ConnectDev, String ConnDevIP, int ConnPort)
 {
     ConnectDev.Connect(ConnDevIP, ConnPort);
 }
 public virtual void Connect(string host, int port)
 {
     client.Connect(host, port);
 }
Beispiel #48
0
 //Creamos un cliente y nos conectamos al ip y puerto del sv
 public void SetupClient()
 {
     myClient = new NetworkClient();
     RegisterClientMsgs();
     myClient.Connect("127.0.0.1", 8080);
 }
Beispiel #49
0
 public void Connect()
 {
     serverIp = FindObjectOfType <InputField>().text;
     client.Connect(serverIp, port);
 }
 public TestGameClient(int port)
 {
     m_Transport     = new TestTransport("127.0.0.1", port);
     m_NetworkClient = new NetworkClient(m_Transport);
     m_NetworkClient.Connect("127.0.0.1:1");
 }
 public void ClientConnect()
 {
     ClientScene.RegisterPrefab(moneyBagPrefab);
     NetworkClient.RegisterHandler <ConnectMessage>(OnClientConnect);
     NetworkClient.Connect("localhost");
 }
Beispiel #52
0
 /// <summary>
 /// Connect client to a NetworkServer instance.
 /// </summary>
 /// <param name="uri">Address of the server to connect to</param>
 public void Connect(Uri uri)
 {
     NetworkClient.Connect(uri);
 }
Beispiel #53
0
        public void Init()
        {
            ScanForHandlers();

            client = new NetworkClient(managerAddress, connector);
            client.Connect();

            OnInit();
        }
    private void ConnectNetworkClient(string host = "localhost", int port = 7777)
    {
        //Basic Unity Networking Client, note there are other ways to do this
        //Referr to the unity documentation on Unity Networking for more info.
        _network = new NetworkClient();
        _network.RegisterHandler(MsgType.Connect, OnConnected);
        _network.RegisterHandler(GameServerMsgTypes.OnAuthenticated, OnAuthenticated);
        _network.RegisterHandler(GameServerMsgTypes.MsgRecieverExampleResponse, OnMsgRecieverExampleResponse);
        _network.RegisterHandler(MsgType.Error, OnClientNetworkingError);
        _network.RegisterHandler(MsgType.Disconnect, OnClientDisconnect);

        _network.RegisterHandler(GameServerMsgTypes.OnPlayStreamEventReceived, OnReceivedPlayStreamEvent);
        _network.RegisterHandler(GameServerMsgTypes.OnSendFriendsList, OnReceivedFriendList);
        _network.RegisterHandler(GameServerMsgTypes.OnTitleNewsUpdate, OnTitleNewsUpdate);

        //If this fails, it will automatically disconnect from the server.
        if (IsLocalNetwork)
        {
            host = this.host;
            port = this.port;
        }
        _network.Connect(host, port);
        Debug.LogFormat("Network Client Created, waiting for connection on ServerHost:{0} Port:{1}", host, port);

        /*  I wanted to expand on the statement above,  Unity Networking has a NetworkingManager that is a 
         *  monobehaviour that you can instantiate into the scene and it also has a HUD for debugging, 
         *  Some like to use that over the direct client.  So instead of creating a NetworkingClient
         *  You could just instantiate a NetworkManager Game Object Prefab, and get a refrence to it's Client
         *  property.  This would allow you to virtually do the same code above, but on that game object.
         *  For this example, I'm taking the most simple and direct path.
         */



    }
Beispiel #55
0
 private void ClientSetup()
 {
     NetworkClient client = new NetworkClient();
     client.RegisterHandler(MsgType.Connect, OnConnected);
     client.Connect(server, port);
 }
Beispiel #56
0
        public void Commands_TickJumpBack()
        {
            TestTransport.Reset();

            var random = new Random(9904);

            var serverTransport  = new TestTransport("127.0.0.1", 1);
            var clientTransport  = new TestTransport("127.0.0.1", 2);
            var snapshotConsumer = new NullSnapshotConsumer();

            var server = new NetworkServer(serverTransport);
            var client = new NetworkClient(clientTransport);

            client.Connect("127.0.0.1:1");

            server.InitializeMap((ref NetworkWriter data) => { data.WriteString("name", "TestMap"); });

            server.Update(this);

            var sentCommands = new Dictionary <int, MyCommand>();

            m_ReceivedCommands.Clear();

            var  RUNS       = 100;
            var  serverTick = 0;
            var  clientTick = 10;
            bool jumped     = false;

            while (serverTick < RUNS)
            {
                server.Update(this);
                server.HandleClientCommands(serverTick, this);
                ++serverTick;
                server.SendData();

                client.Update(this, snapshotConsumer);

                if (clientTick < RUNS)
                {
                    if (!jumped && clientTick == 50)
                    {
                        jumped     = true;
                        clientTick = 45;
                        for (int i = serverTick; i < 50; ++i)
                        {
                            sentCommands.Remove(i);
                        }
                    }

                    client.QueueCommand(clientTick, (ref NetworkWriter writer) =>
                    {
                        var sent        = new MyCommand();
                        sent.intValue   = random.Next(-1000, 1000);
                        sent.boolValue  = random.Next(0, 1) == 1;
                        sent.floatValue = (float)random.NextDouble();

                        sentCommands.Add(clientTick, sent);
                        sent.Serialize(ref writer);
                    });
                }
                ++clientTick;
                client.SendData();
            }

            foreach (var sent in sentCommands)
            {
                sent.Value.AssertReplicatedCorrectly(m_ReceivedCommands[sent.Key], false);
            }
        }
Beispiel #57
0
	public void OnMatchJoined(JoinMatchResponse matchJoin) {
		if (matchJoin.success) {
			connectionStatus = "Joined Match. Connecting...";

			joiningPanel.gameObject.SetActive(false);

			if (matchCreated) {
				connectionStatus = "Error. Cannot connect.";
				return;
			}

			Utility.SetAccessTokenForNetwork(matchJoin.networkId, new NetworkAccessToken(matchJoin.accessTokenString));
			NetworkClient myClient = new NetworkClient();
			myClient.RegisterHandler(MsgType.Connect, OnConnected);
			matchInfo = new MatchInfo(matchJoin);
			myClient.Connect(matchInfo);
		} else {
			connectionStatus = "Join match failed";
		}
	}